I would like to build a regex that grep all characters between [[xxx]], with new line.
"dgghr" and "dfgdfgfd
To exclude a character, use a negated class :
[^x] matches any character but
] has a special meaning in character classes, you have to escape it :
Now simply excluding
] could give you undesirable results if the text bewteen double brackets can contain brackets :
\[\[[^\]]*\]\] wouldn't match
I believe the only problem with your regex is that it is greedy : it will match as much as it can, rather than stopping to the first match, so the
[\S\s] class will match closing brackets as long as there are others that can be matched by
So what I propose is to make your
[\S\s]+ part lazy/non-greedy, as in the following :
You can try it on regex101.