简体   繁体   中英

Python regex to remove two digit number in between strings

I have a String input and I need to remove two digit numbers from the string, wherever it appears.

Example:

str = "abcdef12efgh abc12 abc12345defg 12 12abc abc123"

The required output should be:

abcdefefgh abc abc12345defg abc abc123

I am able to remove the two digits prefixed/suffixed by '< space >', but not 'abcdef12efgh'.

Is there a regex for doing this? Or should I iterate through the string and remove the two digit numbers checking if the string has non-numeric character before/after it.

This might work. (?<!\\d)\\d{2}(?!\\d)

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