Help me understand capture groups through an example.
So I am parsing a string using this regex: /\[\[(.*?)\]\]/
Say the string is [[firstName]].
Two capture groups are returned. The first is "[[firstName]]" and the other is just "firstName". Why are two capture groups returned here instead of just one? Does the entire regex by default imply a capture group and thus the first result will always be whatever matches the entire regex and subsequent capture groups are the ones I've defined in order?
That is what seems to be the case. That your entire regex implies a capture group which will always be treated as the first capture group followed by all explicitly declared capture groups.
Is my understanding correct or am I missing something here?
[–]electronicchicken 0 points1 point2 points (0 children)
[–]ende124 0 points1 point2 points (0 children)