更新:根据关于我的问题含糊不清的评论,我增加了问题的细节.
(术语:用语言来指代任何一系列字母数字字符.)
我正在寻找一个正则表达式来匹配以下,逐字:
我想匹配以下内容,但不是逐字逐句,而是删除撇号:
'foo'会匹配foo.foo''bar将匹配foo和bar.''foo将匹配foo和''foo''对foo.示例 这些将逐字匹配:
'boutit'spersons'但这些将被忽略:
'''并且,因为'open',open将匹配.
mač*_*ček 21
(?=.*\w)^(\w|')+$
'bout # pass
it's # pass
persons' # pass
' # fail
'' # fail
Run Code Online (Sandbox Code Playgroud)
NODE EXPLANATION
(?= look ahead to see if there is:
.* any character except \n (0 or more times
(matching the most amount possible))
\w word characters (a-z, A-Z, 0-9, _)
) end of look-ahead
^ the beginning of the string
( group and capture to \1 (1 or more times
(matching the most amount possible)):
\w word characters (a-z, A-Z, 0-9, _)
| OR
' '\''
)+ end of \1 (NOTE: because you're using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \1)
$ before an optional \n, and the end of the
string
Run Code Online (Sandbox Code Playgroud)
/('\w+)|(\w+'\w+)|(\w+')|(\w+)/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21869 次 |
| 最近记录: |