0

I’m trying to match occurrences of the word “organization” but not when it occurs in between square brackets:

Example strings:

The organization “[organization name]” must contain at least one user per organization. The ID [id] for [organization] must contain digits only

I try to use:

(?:^|\s)(organization)(?!])

but the only flavor supported in the application I'm using is POSIX Extended Regex.

revo
  • 47,783
  • 14
  • 74
  • 117
  • Are you trying to replace? – revo Apr 09 '18 at 12:07
  • Most probably the tool you are using supports returning just what is captured. Try `\[[^][]*]|\b(organization)\b`. To remove those occurrences, use `(\[[^][]*])|\borganization\b` and replace with `\1`. BTW, if it is for AHK, it supports PCRE, not POSIX ERE. – Wiktor Stribiżew Apr 09 '18 at 12:17

2 Answers2

0

occurrences of the word “organization” but not when it occurs in between square brackets

The shortest way would be (?!<\[)(organization)(?!=\]).

The only flavor supported in the application I'm using is POSIX Extended Regex.

Since negative lookarounds are not available to you: ([^[]|^)(organization)([^]]|$).

This fails to match [organization and organization]; if you want it to succeed when either the open or close bracket is missing, you have to explicitly add those cases:

([^[]|^)(organization)([^]]|$)|\[(organization)([^]]|$)|([^[]|^)(organization)\]
sshine
  • 15,635
  • 1
  • 41
  • 66
0

Yes, you are right the occurrences in brackets shouldn't match

Thank you for the help! I finally used this variant:

([^\[]|^)(organization)([^\]]|$)

I had to escape the [ in the range