简体   繁体   中英

Regex don't match previous matches?

If I have a string "aabb", I am looking to match (a, b, ab). I want to prioritize longer matches, and not match a match twice.

eg output would be a, ab, b

I tried have the following: [(\\bab\\b)|(a)|(b)] & [\\b(ab|a|b)\\b]

But it outputs a, a, b, b

Those word boundaries in your regex don't match in your input. Just use only

/ab|a|b/

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