4

I got following String:

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

And want to have the "XX,X", so i build following regular expression:

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

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

It didn't match. Do you have any suggestions? The String is definitely in there. var_dump($match) gives me an empty array.

Thank you!

Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
PhilipB
  • 329
  • 2
  • 16

2 Answers2

3

Problem is in the newline. In your regex, there is \n. Use \r\n instead and it will work.

Martin Heralecký
  • 5,649
  • 3
  • 27
  • 65
  • Glad to hear that :) – Martin Heralecký Oct 22 '15 at 13:07
  • 3
    Just a word of caution: that may work in this specific case, but it's better to just make your regexp be newline-unaware by using a modifier to let whitespace or the dot span over any possible newlines. – klaar Oct 22 '15 at 13:10
0

Considering X as digit in your string:

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

preg_match_all($pattern, $string, $match);
scoolnico
  • 3,055
  • 14
  • 24