I want to extract texts that are between /nr AND an opening square bracket or comma plus space, like this
[A/nrf, B/cc, C/nrf, (/w, D/nr, )/w, ,/w, E/p, F/rr, G/ude1]
I want both A and D. I have tried (?!,\s)(?!\[)([^,]+)/nr(?=,)
but it only matches D. Could anyone help please?
You want to match A and D, but according to the logic in the comment extract texts that are between /nr AND an opening square bracket or comma plus space
this will give you A, C and D.
(?:\[|, )([^,]+)/nr
You could use a capturing group to capture what you want and match what you want in front and after the group.
Explanation
(?:\[|, )
Non capturing group, match either [
or a comma and a space([^,]+)
Capture in group 1 matching 1+ times not a comma/nr
Match /nr
Regex demo
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