简体   繁体   中英

match with overlapping - only 3 chars but not 4 - regex

i want to write a regex that will give me all chars that are in between exactly 3 digits. for example:
111a333b444 will return a and b . however, 1111a333b444 will return only b because there are more than 3 digits to the left of a . because there is an issue of overlapping here i used a look ahead regex such as:
matches = re.finditer(r'(?=([\\d]{3}(.){1}[\\d]{3}))',str) but in the second example above it also matches 111a333 .

anyone has an idea for a regex that will match?

thanks a lot

Try this

(?<=(?<!\d)\d{3})[^\d]+(?=\d{3}(?!\d))

See it here on Regexr

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