dongyounai6281 2012-10-11 20:23
浏览 25

RegEx模式不匹配php,但在c#/ java / etc中

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: search string example 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

  • 写回答

2条回答 默认 最新

  • dongmei5168 2012-10-11 20:28
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料