[英]regex to escape a part of string
I am new to python and I need to remove 'Rs.'我是 python 的新手,我需要删除“Rs”。 from 'Rs.
从'卢比。 150.00'.But if I remove '.'
150.00'。但是如果我删除 '.' it removes dot from numeric digits also.
它也从数字中删除点。 Following is my code:
以下是我的代码:
price = re.sub('/[^0-9_.]\Rs.\/', '','Rs. 150.00')
Any help will be appreciated.任何帮助将不胜感激。
Can't you simply do string replacement:你不能简单地做字符串替换:
>>>'Rs. 150.00'.replace('Rs.', '').strip()
'150.00'
Provided that you have more details in the string:假设您在字符串中有更多详细信息:
>>> re.search(r'\d+\.\d+', 'hello Rs. 150.00').group()
'150.00'
>>> re.search(r'\d+\.\d+', 'hello Rs. 150.00 and some more text').group()
'150.00'
This regular expression doesn't replace but finds a match for the digits.此正则表达式不会替换但会找到数字的匹配项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.