What's the regular expression that matches a square bracket?
https://stackoverflow.com/questions/928072
- |
OTHER TIPS
Try using \\[
, or simply \[
.
Are you escaping it with \
?
/\[/
Here's a helpful resource to get started with Regular Expressions:
In general, when you need a character that is "special" in regexes, just prefix it with a \
. So a literal [
would be \[
.
If you're looking to find both variations of the square brackets at the same time, you can use the following pattern which defines a range of either the [
sign or the ]
sign: /[\[\]]/
If you want to match an expression starting with [
and ending with ]
, use \[[^\]]*\]
.
does it work with an antislash before the [
?
\[
or \\[
?
If you want to remove the [
or the ]
, use the expression: "\\[|\\]"
.
The two backslashes escape the square bracket and the pipe is an "or".
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow