Regular expression for preg_match

I got the following line:

ElFTkSuQmCC" alt="" width="auto" height="auto" /></td>
<td style="padding: 10px;">XX,X%</t

And I want to have "XX, X", so I am building the following regular expression:

/QmCC" alt="" width="auto" height="auto" \/><\/td>\n<td style="padding: 10px;">(.*?)%/

I tested it online and got a match for XX, X, but when I try to execute it in php with the following code preg_match_all('/REGEX/',$string,$match);

This did not match. Do you have any suggestions? The string is definitely there. var_dump($match)gives me an empty array.

Thanks!

+4
source share
2 answers

The problem is in a new line. In your regex there is \n. Use \r\nand it will work.

+3
source

Given the value of X in the string:

$pattern = '/(\d{2},\d{1,2})/';

preg_match_all($pattern, $string, $match);
0
source

Source: https://habr.com/ru/post/1612752/


All Articles