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.