I have a string like so, "123.234.567 Remove numbers in this string". The output should be "Remove numbers in this string".
The digits in this string follow the pattern xx.xxx.xxxxx...(digits followed by a period), but the number of periods and digits between each period is not static. here are a couple examples. xx.xxxxxx.xxxx.xxxxxxxx, x.xx.xxxx.xxxxxxxx.xx.xxxxx, x.xx.xxxxxx, etc.
How can I remove these digits followed by periods in regex?
So far I have something like this:
patt = re.compile('(\s*)[0-9].[0-9]*.[0-9]*(\s*)')
But this only works for a specific format.
^
to match the beginning of the string.\d+
to match any number of digits.\.
to match a literal .
character\.\d+
in a group with ()
so you can quantify it to match any number of them.re.sub()
to replace it with an empty string to remove the match.patt = re.compile(r's*^\d+(?:\.\d+)+\s*')
string = patt.replace('', 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.