简体   繁体   中英

regex ___(?=[.]*)

I have this regex

___(?=[.]*)

https://regex101.com/r/Ot6Bua/1

which matches this

在此处输入图像描述

whereas I want to match all _ _ _ but if there are 4 _ like for first one I want to match the 3 _ just before (

I can't find how with lookaround regex

In the pattern ___(?=[.]*) this part (?=[.]*) is always true as it asserts optional dots to the right. So it will match the first 3 underscores as the regex goes from left to right

You might assert either ( ) or , to the right instead:

___(?=[(),])

Regex demo

Another option to match the last 3 underscores is using a negated lookahead, first matching ___ and then assert not _ to the right

___(?!_)

Regex demo

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