I am trying to extract from this kind of string ou=persons,ou=(.*),dc=company,dc=org
the last string immediately preceded by a coma not followed by (.*). In the last case, this should give dc=company,dc=org
.
Looking on regex, this seems to be a positive look behind (preceded by) of a negative look ahead.
So I have achieve this regex: (?<=(,(?!.*\Q(.*)\E))).*
, but it returns ,dc=company,dc=org
with the coma. I want the same thing without the coma. What I am doing wrong?
The comma appears because the capturing group contains it.
You can make the outside capture group noncapturing with (?:)
(?<=(?:,(?!.*\Q(.*)\E))).*
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