sidewinder
sidewinder

Reputation: 3163

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.

Upvotes: 0

Views: 133

Answers (1)

Zach Kelling
Zach Kelling

Reputation: 53819

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

Upvotes: 5

Related Questions