PHP regex分隔符,重点是什么? [英] PHP regex delimiter, what's the point?

查看:135
本文介绍了PHP regex分隔符,重点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么PHP正则表达式具有周围的定界符?似乎更清楚是否将任何模式修饰符作为参数传递给正在使用的任何函数.

Why do PHP regexes have the surrounding delimiters? It seems like it would be more clear if any pattern modifiers were passed in as a parameter to whatever function was being used.

推荐答案

没有技术原因必须如此.

There is no technical reason why it has to be like this.

如注释中所述,底层库不需要将标志作为正则表达式的一部分进行传递-实际上,扩展程序必须剥离这些标志并将其作为单独的参数传递.

As noted in a comment, the underlying library does not require that flags be passed as part of the regexp - in fact, the extension has to strip these off and pass them as a separate argument.

似乎原始的实现者试图使它看起来像grep/sed/awk/perl/etc,以便那些使用这些工具的程序员更加熟悉.

It appears as though the original implementer was trying to make it look like grep/sed/awk/perl/etc so that it is more familiar to programmers coming from those tools.

这篇关于PHP regex分隔符,重点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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