I'm trying to find a substring that contains a "]" without a "|" in front of it. How can I possibly do this with regex?
/(?<!\|)\]/ is the regex you need.
?<! is a zero-width assertion also known as "negative lookbehind." This essentially means match ], but "look behind" and assert that the previous character isn't a |
/(?<!\|)\]/
Use negative lookbehind.
For java :
Pattern regex = Pattern.compile("(?<!\\|)\\[");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With