Hey Experts i am new to regex.I am really confused by studying this regex.I have found something which is very difficult to understand for me.The thing is the use of question mark and equal to symbol in regex.An eg :
嘿专家我是regex的新手。我真的很困惑研究这个正则表达式。我找到了一些很难理解的东西。事情是在正则表达式中使用问号和等于符号。例如:
"(?<=\d)(\s)(?=[\d-])"
I just need to know the use of ?=
in this regex code..I have searched google many times in this case but i didnt find any solution there.So i came here It will be a great help for me if you answer this one correctly for me ..:) ..
我只需要知道在这个正则表达式代码中使用?=我已经在这种情况下多次搜索谷歌但我没有找到任何解决方案那里。所以我来到这里如果你回答这个问题对我来说将是一个很大的帮助对我来说正确.. :) ..
Thanks in advance ..
提前致谢 ..
2 个解决方案
#1
6
At least in JavaScript, the ?=
matches a suffix but excludes it from capture. ?=
excludes the expression from the entire match. For more information, see this question and it's corresponding answers.
至少在JavaScript中,?=匹配后缀但将其从捕获中排除。 ?=从整个匹配中排除表达式。有关更多信息,请参阅此问题及其相应的答案。
#2
8
This is a lookahead.
这是一个先行者。
The part before is only matched if followed by [\d-]
之前的部分仅在后跟[\ d-]时匹配
You should notice the start of the expression is, symmetrically, a lookbehind.
您应该注意到表达式的开头是对称的,是一种后视。
Both groups are not capturing. To sum it up, this regular expression matches a space following a digit and followed either by a digit or a minus sign. For example it matches the space in "3 4"
.
两组都没有抓到。总而言之,这个正则表达式匹配数字后面的空格,后跟数字或减号。例如,它匹配“3 4”中的空格。
Be careful that many languages/engines don't support lookbehind, for performance and predictability reason (see this interesting article for example).
因为性能和可预测性原因,请注意许多语言/引擎不支持lookbehind(例如,请参阅这篇有趣的文章)。
#1
6
At least in JavaScript, the ?=
matches a suffix but excludes it from capture. ?=
excludes the expression from the entire match. For more information, see this question and it's corresponding answers.
至少在JavaScript中,?=匹配后缀但将其从捕获中排除。 ?=从整个匹配中排除表达式。有关更多信息,请参阅此问题及其相应的答案。
#2
8
This is a lookahead.
这是一个先行者。
The part before is only matched if followed by [\d-]
之前的部分仅在后跟[\ d-]时匹配
You should notice the start of the expression is, symmetrically, a lookbehind.
您应该注意到表达式的开头是对称的,是一种后视。
Both groups are not capturing. To sum it up, this regular expression matches a space following a digit and followed either by a digit or a minus sign. For example it matches the space in "3 4"
.
两组都没有抓到。总而言之,这个正则表达式匹配数字后面的空格,后跟数字或减号。例如,它匹配“3 4”中的空格。
Be careful that many languages/engines don't support lookbehind, for performance and predictability reason (see this interesting article for example).
因为性能和可预测性原因,请注意许多语言/引擎不支持lookbehind(例如,请参阅这篇有趣的文章)。