Search code examples
regex

What's the regular expression that matches a square bracket?


I want a regex that matches a square bracket [. I haven't found one yet. I think I tried all possibilities, but haven't found the right one. What is a valid regex for this?


Solution

  • How about using backslash \ in front of the square bracket. Normally square brackets match a character class.