I'm reading a chapter in a book about regular expressions, and the author has written one which should match a particular text. There's only part of it that I have a quarrel with however. That part is looking for [sometexthere].
And the expression he wrote goes like this:
Okay, so first he escapes the square bracket - /\[ so he'll find that.
Then he uses the round brackets (()) to group the text in the middle, so that later it can be referred to as $1.
Then he uses [^\]]+ to state that he wishes for there to be text that isn't a squared closing bracket, and then he simply adds the closing bracket. Why doesn't he escape the last bracket?
I'm sorry, this answered itself:
The square bracket doesn’t need to be escaped with a backslash because there is no unescaped opening square bracket.
This topic is now closed. New replies are no longer allowed.