简体   繁体   中英

Help with a regular expression - Python

Lets assume I have the following string:

string = "xxx abc123 xxx"

I want the regular expression to replace the digits in the string that begin with 'abc'. I have tried the following, but with no luck:

re.sub(r'\d{1,3}\babc','456',string)

Thanks.

re.sub(r'(?<=abc)\d{1,3}', '456', string)

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