简体   繁体   English

如何不捕获正则表达式中的竖线?

[英]How to not capture vertical bar in regex?

I have this regex 我有这个正则表达式

([=|"| |_|\\w]*) , but regex101.com is telling me that | is one of the characters that's included in the group to be able to match, but I just want the characters = or " or ([=|"| |_|\\w]*) ,但是regex101.com告诉我|是该组中可以匹配的字符之一,但我只希望这些字符=" or or _ or \\w to be matched. _\\w进行匹配。

Does anyone know whats wrong? 有人知道怎么了吗?

Thanks 谢谢

Inside a character sets ( [] ) | 在字符集中( []| has no special meaning (it will match literally). 没有特殊含义(它将在字面上匹配)。 In fact character sets have implicit or on their members. 实际上,字符集具有隐式在其成员上。 Just use [=" _\\w]* 只需使用[=" _\\w]*

You just need to use ([="\\s_\\w]*) . It will match any of the combination of the elements. 您只需要使用([="\\s_\\w]*) ,它将匹配元素的任何组合。

[] : Matches a single character that is contained within the brackets [] :匹配括号中包含的单个字符

There is no need for | 不需要| inside [] 里面[]

(?:=|"| |_|\w)*

You can use this. 您可以使用它。 | inside [] is just a character without special meaning. inside []只是一个没有特殊含义的字符。

no need for the | 不需要| , inside of [] it is already implied 的内部[]它已经暗示

([="\s_\w]*)

^is basically the exact thing you are trying to do. ^基本上就是您要尝试做的事情。

unless you meant this: 除非您的意思是:

([=]|["]|[\s]|[_]|[\w]*)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM