How can one or more regular expressions be matched consecutively?

Source: Internet
Author: User
How can one or more regular expressions be matched consecutively? When I capture the train fare, I encountered this problem. some train fares only come out of one type, and some may come out of several types. how can I use one expression to continuously match one or more trains? For example, the following are three possible results: "& lt; td & gt; & nbsp; 234 RMB for hard seat & lt; br & nbsp;/& gt; & nbsp; & n how can one or more regular expressions be matched consecutively?
When I capture the train fare, I encountered this problem. some train fares only come out of one type, and some may come out of several types. how can I use one expression to continuously match one or more trains?

For example, the following are three possible results:

"234 yuan for hard seat Hard sleeper 391/407/420 yuan 613/638 yuan for soft sleeper ";
"234 yuan for hard seat Hard sleeper 391/407/420 yuan ";
"234 yuan for hard seat ";

I want to use the following method, but it does not seem to work. I can only get the last fare. why?
Preg_match ('# (\ s + (.*?) ) + # Is ', $ singleShift, $ piaojia); // fare

Thank you!


------ Solution --------------------
$ SingleShift ="234 yuan for hard seat
 Hard sleeper 391/407/420 yuan
 613/638 yuan for soft sleeper
 ";
Preg_match_all ('#(? : \ S + (.*) ) + # IsU ', $ singleShift, $ piaojia );
Print_r ($ piaojia [1]);
Array
(
[0] => 234 yuan for a hard seat
[1] => hard sleeper 391/407/420 yuan
[2] => 613/638 yuan for a soft sleeper
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.