加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 05:56:54 所属栏目:百科 来源:网络整理
导读:^ *(?=.* [0-9]).* $ 我看到这张贴在某人的代码中.这是一个有效的正则表达式吗?我知道吗?应该像abc一样使它之前的项目可选吗?使c可选.但是?是一个捕获支架的开始.那是什么意思? 解决方法 ?单独表示:选择匹配之前的内容. 但是,(?..)用于断言…… 在
^ *(?=.* [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.)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读