PHP中的详细正则表达式? [英] Verbose regular expressions in PHP?

查看:49
本文介绍了PHP中的详细正则表达式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 php.net 上搜索我找不到任何对 php 中详细正则表达式的支持.这是我不知道如何搜索它的错,还是 php 没有实现它的错?

Searching on php.net I was not able to find any support for verbose regular expressions in php. Is this my fault for not knowing how to search for it, or is it php's fault for not implementing it?

如果php没有这个功能,除了把正则表达式拆分成更小的部分,还有其他的方式来注释正则表达式吗?

If this feature is lacking from php, is there any other way to comment regular expressions other than breaking them up into smaller segments?

推荐答案

你也可以在正则表达式中设置'expanded'模式修饰符,只要它的第一个字符超过
分隔符.

You can also set 'expanded' mode modifier within the regex as long as its the first char past the
delimiter.

= '/(?x)
                     # A comment
     (               # (1 start), some capture
        . 
     )               # (1 end)
  /';

和/或,它也应该在 //x 上下文中可用

And/Or, it should also be available within //x context

'/
                   # A comment
   (               # (1 start), some capture
        . 
   )               # (1 end)
/x';

或者,您可以在代码内自由移入/移出 x-mode

Or, you can freely move in/out of x-mode within the code

'/((?x)            # (1 start), some capture
        .
       (?-x: A )   # ' A ' 
   )               # (1 end)
/'

这篇关于PHP中的详细正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆