Which regular expression matches a square bracket?

I want the regular expression to match the square bracket [ . I haven't found it yet. I think I tried all the possibilities, but did not find the right one. What is the correct regular expression for this?

+58
regex
May 29 '09 at 20:49
source share
7 answers

How to use backslash \ before square bracket. Usually square brackets correspond to a character class.

+72
May 29 '09 at 20:51
source share

Try using \\[ or just \[ .

+28
May 29 '09 at 20:51
source share

Do you avoid it with \ ?

 /\[/ 

Here's a useful resource that you can start with regular expressions:

Regular-Expressions.info

+9
May 29 '09 at 20:52
source share

If you want to find both variants of square brackets at the same time, you can use the following template, which defines the range of the character [ or character ] : /[\[\]]/

+4
Nov 10 '09 at 10:32
source share

In general, when you need a character that is "special" in regular expressions, just attach it to \ . Thus, the letter [ will be \[ .

+3
May 29 '09 at 20:52
source share

Does this work with antispas before [ ?

\[ or \\[ ?

+2
May 29 '09 at 20:51
source share

If you want to delete [ or ] , use the expression: "\\[|\\]" .

Two backslashes come out of the square bracket, and the pipe is an "or".

0
Oct 06 '15 at 21:36
source share



All Articles