I want to do with regex (regular expression), as for example (if it's javascript):
var str = '[abc\[0123\]] [efg\[987\]h] [olá \[mundo\]!] [foo [baz]]';
str.match(/\[(.*?)\]/g);
Output:
["[abc[0123]", "[efg[987]h", "[olá [mundo]!", "[foo [baz]"]
Or
var str = '{abc\{0123\}} {efg\{987\}h} {olá \{mundo\}!} {foo {baz}}';
str.match(/\{(.*?)\}/g);
Output:
["{abc{0123}", "{efg{987}", "{olá {mundo}", "{foo {baz}"]
But I would like the first one to ignore non-escaped places like [foo [baz]]
and take only [baz]
and escaped, like this:
["[abc[0123]]", "[efg[987]h]", "[olá [mundo]!]", "[baz]"]
And in the second it returns this:
{"{abc{0123}}", "{efg{987}h}", "{olá {mundo}!}", "{baz}"]
My intention initially is to study, but I also intend to use in things like a structure that is similar to CSS selectors, so for example:
input[name=\[0\]], input[name=foo\[baz\]\[bar\]]
I would return this:
[0], [1]
Or a map of URLs that I want to create:
/{nome}/{foo\{bar}/{baz\{foo\}}/
And I would return this:
{nome}, {foo{bar}, {baz{foo}}
What I want is to ignore the escaped characters, how can I do this? You can provide an example in any language, the most important is Regex