I try to check a index string (e.g. $string = "[index]") with a regular expression. This index must be checked against the illegal characters [ and ] inside the index name. So for example [in[dex] must fail.
My first try:
/^\[[^\[\]]*\]$/
So the the string must start and end with [ and ]. With a negated character class I now try to make inline square brackets illegal but this doesn’t work propably.
Any ideas?
Thanks in advanced,
Johnny
Edit: I’m very confused. I rerun the tests I wrote for this and it works fine now. Think I have missed something when working in the history of my editor. Thanks for help to everyone.
This
/^\[[^[\]]+\]$/worked for me./^\[begins with a bracket[^open “not” syntax[\]exclusion characters]+close not and say we only want 1+ things which pass the not syntax (change to asterisk to match [])\]$/Expression will end with the closing bracket.