这是怎么回事?操作符在正则表达式中工作?

前端之家收集整理的这篇文章主要介绍了这是怎么回事?操作符在正则表达式中工作?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
^ *(?=.* [0-9]).* $

我看到这张贴在某人的代码中.这是一个有效的正则表达式吗?我知道吗?应该像abc一样使它之前的项目可选吗?使c可选.但是?是一个捕获支架的开始.那是什么意思?

解决方法

?单独表示:选择匹配之前的内容.

但是,(?..)用于断言……

在你的情况下,(?=是一个前瞻断言,意思是:如果只是匹配(括号中的内容),则跟随.

Reference


(?: … )

Non-capturing parentheses. Groups the included pattern,but
does not provide capturing of matching text. Somewhat more efficient
than capturing parentheses.

(?> … )

Atomic-match parentheses. First match of the parenthesized
subexpression is the only one tried; if it does not lead to an overall
pattern match,back up the search for a match to a position before the
“(?>”

(?# … )

Free-format comment (?# comment ).

(?= … )

Look-ahead assertion. True if the parenthesized pattern
matches at the current input position,but does not advance the input
position.

(?! … )

Negative look-ahead assertion. True if the parenthesized
pattern does not match at the current input position. Does not advance
the input position.

(?<= … )

Look-behind assertion. True if the parenthesized pattern
matches text preceding the current input position,with the last
character of the match being the input character just before the
current position. Does not alter the input position. The length of
possible strings matched by the look-behind pattern must not be
unbounded (no * or + operators.)

(?<! … )

Negative Look-behind assertion. True if the parenthesized pattern does not match text preceding the current input position,with the last character of the match being the input character just before the current position. Does not alter the input position. The length of possible strings matched by the look-behind pattern must not be unbounded (no * or + operators.)

猜你在找的正则表达式相关文章