【问题标题】:preg_match with regular expression not working in php5.6.10?preg_match 与正则表达式在 php5.6.10 中不起作用?
【发布时间】:2015-09-21 22:53:09
【问题描述】:

我正在尝试匹配正则表达式

/getData/?p<1d>[^/] 

/getData/1

使用preg_match,但这不适用于 php 5.6.10,而它在 php 5.3.8 上运行良好。

请告诉我如何解决这个问题?

提前致谢。

【问题讨论】:

  • 你能用 PHP 5.3.8 展示你的工作代码吗?

标签: php regex preg-match php-5.3


【解决方案1】:

您忘记在命名捕获组 id 周围添加括号,并且您需要删除存在于 &lt;id&gt; 之前的 p

/getData/(?<id>[^/])

DEMO

【讨论】:

  • (? 组名不能以数字开头我在尝试你的方法@Avinash时收到此错误
  • 我以为是i。但我正确地包含在我发布的演示链接中。
猜你喜欢
  • 2013-06-19
  • 1970-01-01
  • 1970-01-01
  • 2021-09-01
  • 2012-09-01
  • 1970-01-01
  • 2012-01-05
  • 2020-07-08
相关资源
最近更新 更多