正则表达式,“只是组,不捕获”,似乎不起作用 [英] Regular expression, "just group, don't capture", doesn't seem to work

查看:91
本文介绍了正则表达式,“只是组,不捕获”,似乎不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x = "abcdefg"
x = x.match(/ab(?:cd)ef/)

不应该是什么?它不是,它实际上是abcdef

shouldn't x be abef? it is not, it is actually abcdef

为什么我的?:没有任何影响? (当然我的理解很可能是错的)

Why is it that my ?: not having any effect? (of course my understanding could very well be wrong)

推荐答案

(?:...)匹配,它只是不为 \1 / $ 1 / .groups(1) / etc。

(?:...) still matches, it just doesn't create a new group for purposes of \1/$1/.groups(1)/etc.

这篇关于正则表达式,“只是组,不捕获”,似乎不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆