[英]Regex how to match a word without a character in it
How can I match something like {anyWord}
but exclude anything that has an underscore at the beginning, like this: {_doNotMatchThis}
? 如何匹配类似{anyWord}
内容,但排除开头带有下划线的内容,例如: {_doNotMatchThis}
?
Input: 输入:
hi there {matchPlease}{andThis}, just doing some regex {_notThis}
Desired matches: 所需的比赛:
{matchPlease}
{andThis}
Without that condition of excluding the starting {_
, I know that this regex pattern works well: \\{\\w+\\}
没有排除起始{_
,我知道此regex模式可以很好地工作: \\{\\w+\\}
I've tried to modify that to be, \\{!_\\w+\\}
, basically saying, "match anything that starts with {
, then has a word that does not start with _
, then ends in }
". 我试图将其修改为\\{!_\\w+\\}
,基本上是说:“匹配以{
开头的任何单词,然后以不以_
开头的单词,然后以}
结尾的单词”。 Thanks. 谢谢。
How about this? 这个怎么样?
/\{([^_].*?)\}/
And per @Geo and @nhahtdh in the comments, if you want only words: 如果您只想要单词,请在注释中使用每个@Geo和@nhahtdh:
/\{([^_]\w*)\}/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.