我想要一个匹配方括号 [的正则表达式。我还没找到。我想我尝试了所有的可能性,但还是没有找到合适的。什么是有效的正则表达式?
[
在方括号前面使用反斜杠 \怎么样? 通常方括号匹配一个字符类。
\
尝试使用 \\[,或者简单地使用 \[。
\\[
\[
在 [之前用反斜线能起作用吗?
\[ or \\[ ?
你是用 \逃出来的吗?
/\[/
Here's a helpful resource to get started with Regular Expressions:
Regular-expressions.info
In general, when you need a character that is "special" in regexes, just prefix it with a \. So a literal [ would be \[.
如果你想同时找到方括号的两个变体,你可以使用下面的模式来定义 都不是的范围,[符号 或者,]符号: /[\[\]]/
]
/[\[\]]/
如果要删除 [或 ],请使用表达式: "\\[|\\]"。
"\\[|\\]"
两个反斜杠与方括号不符,管道是“ or”。
如果希望匹配以 [开始、以 ]结束的表达式,请使用 \[[^\]]*\]。
\[[^\]]*\]
下面是每个部分的含义(如 Www.regexr.com所解释的) :
对于纯 exgex,它很简单:
1/[] abcde ]/-这是在类中包含“]”的方法。
2 /[abc[de]/ - freely put anything else inside the brackets, including the '['. (Most of the meta-characters lose their special meaning inside '[]').
3 Test(verify) your regex w/ 'grep' or 'vim' etc. first.(They are easy-going guys.)
4如果脚本环境不同意,现在尝试插入’还为时不晚。