【发布时间】:2016-01-03 15:42:35
【问题描述】:
我正在尝试添加 cmets 以使正则表达式更清晰
// Strip any URLs (such as embeds) taken from http://stackoverflow.com/questions/6427530/regular-expression-pattern-to-match-url-with-or-without-http-www
$pattern =
'( # First capturing group
(http|https) # Second capturing grout,matches wither http or https
\:\/\/)? # End of first capturing group, matches :// exactly
[ # Match any char in the following list. the + after the closing bracke means greedy
a-z # Any char between a and z
A-Z # Any char between A and Z
0-9 # Any char between 0 and 9
\.\/\?\:@\- # ./?:@- literally ( any one of them )
_=# # _=# any of these thre chars
]+ # end of list
\. # matches .
( # third caturing group
[ # start of list
a-z # Any char between a and z
A-Z # Any char between A and Z
0-9 # Any char between 0 and 9
\.\/\?\:@\- # ./?:@- literally ( any one of them )
_=# # _=# any of these thre chars
] # end of list
)* # end of capturing group with greedy modifier';
$excerpt = preg_replace("/$pattern/x", '', $excerpt );
但我收到警告
警告:preg_replace():第 280 行中的未知修饰符“/”
我该怎么评论呢?
【问题讨论】:
-
您可能必须将每个部分分开并使用
.运算符将它们连接起来。 -
你只能在字符类中使用 cmets。空格在字符类中总是很重要的,即使使用 x 修饰符。
-
如果使用#作为分隔符,是否可以使用x修饰符制作cmets?