Nar*_*rek 4 php regex preg-match
我有字符串:
FirstWord word2 word3 wrongWord word4 lastWord
想要选择字符串开头FirstWord,结尾lastWord和不包含wrongWord.
我有第一个也是最后一个:
/ firstword(.*?)lastword/i
但排除wrongword不起作用.
尝试:
/ firstword(^ wrongWord*?)lastword/i
/ firstword ^((?! wrongWord).)*lastword/i
更像这样,但没有任何作用.
简单的以下是什么问题?
/^firstword ((?:(?!wrongword).)+) lastword$/i
Run Code Online (Sandbox Code Playgroud)
看到 live demo
正则表达式:
^ the beginning of the string
firstword 'firstword '
( group and capture to \1:
(?: group, but do not capture (1 or more times)
(?! look ahead to see if there is not:
wrongword 'wrongword'
) end of look-ahead
. any character except \n
)+ end of grouping
) end of \1
lastword ' lastword'
$ before an optional \n, and the end of the string
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7595 次 |
| 最近记录: |