I have been banging my head with this for the last hour and a half and cannot make it work. I am trying to create a regular expression for MemoQ's Regex tagger.
I have a series of these:
zzz [xxx]yyy[/xxx] zzz
or
zzz [xxx]yyy[/xxx]
or
[xxx]yyy[/xxx] zzz
or
[xxx]yyy[/xxx]
For example:
TEXT TEXT TEXT [img height=32]logo_small.dds[/img] TEXT TEXT TEXT
I want to transform into a single tag everything from the first open parenthesis to the last closed one, which is:
[img height=32]logo_small.dds[/img]
Please remember that the expression should work regardless of what is inside the parentheses and in between the two. Also please note that could be other text before and after that should not be converted.
You can find the rules for Regex tagger here (should be standard, anyway): https://docs.memoq.com/current/en/Places/regular-expressions.html
I have tried several expressions, the last one being this: \[(.*?)\](.*?)\[(.*?)\]
Thank you for your help and have a great day!
The solutions below do not match nested tags, this is because OP does not require matching nested tags.
If you just need to match strings like
[...]...[...], you can useSee the regex demo. Details:
\[- a[char[^][]*- zero or more chars other than[and]]- a]char.*?- any zero or more chars other than line break chars as few as possible\[[^][]*]- a[char + zero or more chars other than[and]+]char.A bit more comprehensive expression - that would only match the paired tags - would look like
See this regex demo. This matches
\[- a[(\w+)- group 1: one or more word chars\b- word boundary[^][]*- zero or more chars other than[and]chars]- a]char[\w\W]*?- any zero or more chars as few as possible\[/- a[/text\1- same text as captured into Group 1\b- a word boundary[^][]*]- zero or more chars other than[and]chars +]char.