I have been trying to extract some strings or any kinds of values which are enclosed in double squar bracket. i.e. [[hello world]]
or [[12_ nine]]
etc. That's mean anything but which are enclosed in two squar bracket. Please check this URL, where I tried. However, I am explaining below what I did:
/\[[^\]]*\]]/
This pattern can validate anything inside [[]]
. My problem is, it validate also []]
. I am giving two examples what this parttern validate [[Welcome]]
[v2.0]]
. I need second example should not be validated. See the URL, you can understand better.
You need this:
/\[\[[^\]]*\]\]/
Here's how it's defined:
\[\[
[^\]]*
\]\]
(you could keep them unescaped too, it's a matter of style)Note that it won't match strings having square brackets in the middle (e.g. [[ A [B] C]]
). If you want to allow those strings, use
/\[\[.*?\]\]/
If that must be the whole string, as seems to be from your comment below, use
/^\[\[.*?\]\]$/ (if you want to allow brackets inside)
/^\[\[[^\]]*\]\]$/ (if you don't)
^
an $
are end of string anchors and let you test the whole string.