标签: python regex
有一个字符串I bought a beautiful gift for my friend. It cost me US$ 1,500.25. My friend was very happy. But then she asked for a US$1,700 gift
I bought a beautiful gift for my friend. It cost me US$ 1,500.25. My friend was very happy. But then she asked for a US$1,700 gift
我想获得关键字1,500.25之后的第一个双精度数字gift。
1,500.25
gift
如何使用正则表达式做到这一点。
非常感谢。
答案 0 :(得分:1)
您可以使用此正则表达式-
gift.*?(\d+(?:,\d+)*(?:\.\d+)?)
它适用于问题中的示例。可以找到正则表达式说明here
答案 1 :(得分:1)
正则表达式部分为:
gift.*?\d+(?:,\d+)*(?:\.\d+?)
Useful link创建正则表达式。 Tutorial用于正则表达式。