php - 是否有实用程序可以将 POSIX 转换为适用于 PHP 的 PCRE?

标签 php regex posix utilities pcre

<分区>

是否有一个实用程序可以将 POSIX 转换为适用于 PHP 的 PCRE?我对 PCRE 上的 PHP 手册有些困惑,虽然我会尝试查找有关 PCRE 的更多信息,但我想知道是否有人设计了这样的实用程序。

或者,如果有人会解释如何转换以下内容,那也很好:

ereg("^#[01-9A-F]{6}$", $sColor)

但请解释它是如何完成的,而不仅仅是告诉我转换。

最佳答案

preg_match("/^#[01-9A-F]{6}$/", $sColor)<code></code>
<code>In this case you only need to add the two delimiters.<p></p> <p>In perl you can write something like</p></code><pre><code>if ( s =~ /x.+y/ ) { print "match"; }</code></pre>As you can see the actual regular expression is encapsulated in //. If you want to set an option on the regular expression you put it after the second /, e.g. switching the expression to ungreedy by default /x.+y/U<br/> pcre now emulates this behaviour. Though you have to call a function you also have to provide the delimiters and set the options after the second delimiter. In perl the delimiter has to be /, with pcre you can chose more freely
preg_match("/^#[01-9A-F]{6}$/", $sColor)
preg_match("!^#[01-9A-F]{6}$!", $sColor)
preg_match("#^\#[01-9A-F]{6}$#", $sColor) // need to escape the # within the expression here
preg_match("^#[01-9A-F]{6}$", $sColor)
pcre都一样,最好选择一个没有出现在表达式中的字符。

关于php - 是否有实用程序可以将 POSIX 转换为适用于 PHP 的 PCRE?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1023227/

相关文章:

c - 为什么要销毁 pthread_cond_t 和 pthread_mutex_t?

php - 编辑此代码以避免降低性能的更有效方法是什么?

php - 获取简单的 html 文本字段以发布到 mysql 数据库

php - 将 JSON 字符串解析为数据库

c - 在 C 中处理 stdin 上的输入

linux - linux 上的 posix timer_create() 问题

php - 搜索带单引号的文本

电子邮件列表的正则表达式,验证无效的电子邮件地址

正则表达式:获取每一行的一个月

regex - 从字符串中删除第一个字符