I have to parse a text where with is a key word if it is not surrounded by square brackets. I have to match the keyword with. Also, there must be word boundaries on both side of with.
Here are some examples where with is NOT a keyword:
- [with]
- [ with ]
- [sometext with sometext]
- [sometext with]
- [with sometext]
Here are some examples where with IS keyword
- with
- ] with
- hello with
- hello with world
- hello [ world] with hello
- hello [ world] with hello [world]
Anyone to help?
Thanks in advance.
You can look for the word
withand see that the closest bracket to its left side is not an opening bracket, and that the closest bracket to its right side is not a closing bracket:The lookaround expressions don’t stop at line breaks; if you want each line to be evaluated separately, use
[^[\]\r\n]*instead of[^[\]]*.