我想从以下字符串中解析出“ $ 1000.00 ”(一个字符串):
“ 等待了近三个月后,丢了一个书架($ 1,000.00)。”
我应该如何在re.findall()函数中设计正则表达式模式?谢谢!
我尝试过的是re.findall(r"\d+[.,]?\d+", text)
,但我只有:
['1,000','00']
但是,我希望我的输出是: ['$ 1,000.00']
答案 0 :(得分:1)
如何查找带有美元符号,千位分隔符和十进制的价格标签 Python正则表达式指向
money_parser egg正是您需要的:
安装:
switch ((sender as Button).Text)
{
case "1":
serialMonitor.PrintLine("1");
currentPressedCode = currentPressedCode + "1";
break;
case "2":
serialMonitor.PrintLine("2");
currentPressedCode = currentPressedCode + "2";
break;
case "3":
serialMonitor.PrintLine("3");
currentPressedCode = currentPressedCode + "3";
break;
default:
break;
} if (buttonsPressed == 3)
{
if (currentPressedCode == vaultCode)
{
//vault open
serialMonitor.PrintLine("vault");
pcbGreen.BackColor = Color.ForestGreen;
}
}
else
{
// wrong code
serialMonitor.PrintLine("wrong");
MessageBox.Show("Wrong password"); // wrong password messagebox
pcbRed.BackColor = Color.DarkRed;
}
用法:
pip install money_parser
您可以使用类似的内容:
from money_parser import price_str
x = "lost a bookcase ($1,000.00) after waiting for nearly three months."
print(price_str(x))
# 1000.00
x = "lost a bookcase ($1,000.00) after waiting for nearly three months."
result = re.findall(r"\b\$?[\d,.]+\b", x)
注意:
['1,000.00']
,但足以让您
开始。\b\$?[\d,.]+\b