Reputation: 1775
I have a problem with regular expressions in php.
Got the following pattern: ^\s*(\d{8})\s+(.+?)\s+(\d+,\d{2})\s.?\s(.*)$
My search string is like:
12345678 This is a little Product Description with some special characters like ® 16,00 € maybe some text here
I use this php code:
$regex = '/^\s*(\d{8})\s+(.+?)\s+(\d+,\d{2})\s.?\s(.*)$/';
echo preg_match($regex, $input);
But there is no match!
The same regex pattern in java or c# works! Can you explain me what I'm doing wrong?
Here some online regex tester:
PHP: http://regexp-evaluator.de/evaluator/d721ca1ed32d76db960262ba7298cff3/#ergebnis
Java: http://www.regexplanet.com/advanced/java/index.html
Upvotes: 0
Views: 333
Reputation: 145512
You are missing the /u
modifier.
After looking for the price value 0,00 your regex compares for a single character (.?)
between spaces. But the Euro sign €
usually occupies two bytes. This will only work in UTF-8 mode.
Upvotes: 5
Reputation: 4474
if not in multiline mode, the $ only matches the end of the complete string. If there is a newline-character or more data in $input, this may be the cause. In that case, simply put an "m" behind the final delimiter.
Further I wonder if (.+?) is correct. Have your tried (.*) instead?
BurninLeo
Upvotes: 0