简体   繁体   中英

named capturing group inside negative lookbehind regex

I want to avoid catching input as:

:):) but want to catch sa:)ds or simply want to exclude from result if there are two or more of the same tags which are touching one another.

My logic says I need to use negative lookbehind and named capture group but canot make it working and I become unsure if correct way.

I tried with: (?<!(?P<happy>:\\)))(?P=happy) so if I have input as :):) --:)-abc I want to match only from second line ":)"

If you are going to build a regex for .NET don't work with other RegEx engines to test your patterns. That said, you can benefit from variable-length lookbehinds in .NET but not PCRE (engine you're working with).

This would be a workaround in .NET:

(?<happy>:\))(?<!\k<happy>{2,})(?!\k<happy>)

That obviously doesn't work in regex101.com

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM