我想添加註釋,使一個正則表達式更清晰到的意見在PHP
// 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
我應該如何評論這未知的修飾詞「/」?
你可能不得不分開每一塊,並用'.'運算符連接它們。 – segFault
你只能在角色類中留言。即使使用x修飾符,空白在字符類中始終是重要的。 –