Let's see how to write this regular expression.

Source: Internet
Author: User
How can I write this regular expression? & Lt; td & gt; 1234567890 & lt;/td & gt; & lt; td & gt; 1234567890123 & lt;/td & gt; & lt; td & gt; 0987654321 & lt;/td & gt; & lt; td & gt; 3210987654321 & lt;/td & gt; & lt; td & g help me find out how to write this regular expression?
1234567890
1234567890123
0987654321
3210987654321
1324354657
1324354657689

1. the above content, I just want to match the string with a length of 10 is the red text, how do I write regular expressions as long as the number in the td

2. I want to put the red string (with a length of 10) into an array, and the black string (with a length of 13) into an array. what's the best way to do it quickly. As long as the number in td


------ Solution --------------------
Basic code
PHP code
$ S = <TXT123456789012345678901230987654321321098765432113243546571324354657689TXT; preg_match_all ('/(\ d {13}) | (\ d {10})/S', $ s, $ r); print_r ($ r );
------ Solution --------------------
If \ d {10} is placed in front of it, 10 consecutive numbers will be matched first. if 13 consecutive numbers match the first 10, an error will occur. you can change it to the following:
PHP code
Preg_match_all ('/(\ d {10} \ B) | (\ d {13} \ B)/S', $ s, $ r); print_r ($ r );
------ Solution --------------------
(\ D {10}) matches 10 digits. Because each td contains a value greater than or equal to 10 to meet the conditions. Therefore, it is matched in the first submode.

You can use two regular expressions to form two arrays.

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.