如何通过QREGEXP通过菲律宾货币?
我目前正在研究正则是我的正则是:
r"\₱[0-9]*[.]{,1}[0-9]{,2}"
因为QREGEXP是,目前只有它以>₱
开始,除了我的应用程序破裂之外,还有一种方法可以获得以下格式:
100.0
100.00
₱100.00
I am currently studying Regex and I came up in this regex:
r"\₱[0-9]*[.]{,1}[0-9]{,2}"
for QRegExp is and currently It is only good if it starts with ₱
other than that my app is breaking is there a way to get these following formats:
100.0
100.00
₱100.00
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您应该通过更改
\₱
将可选为
[\₱] {0,1}
注意:我始终使用
{0,1}
语法,而不是{,1}
确保下一个开发人员清楚其功能。条件
₱
外部雷格克斯小提琴
之后将不会接受超过2个位置。 /1“ rel =“ nofollow noreferrer”> https://regex101.com/r/dbk1dq/1
You should make
₱
optional by changing\₱
to[\₱]{0,1}
Note: I always use
{0,1}
syntax and not{,1}
to ensure the next developer is clear on what it does.Conditions
₱
External Regex Fiddle
https://regex101.com/r/dBk1Dq/1
不需要
₱
符号之前的逃逸。我还使剩下的速度更加简洁,更快,因此引擎不需要通过使整个小数部分进行可选,但是该组中的小数点是强制性的,我更换了[0-9 ]
带有更多语义\ d
。大概您将需要至少一位数字,因此我将自由更改为*
+
。The escape before the
₱
symbol is not needed. I also made the rest a bit more concise and faster, so the engine doesn't need to uselessly backtrack, by making the whole decimal section optional, but the decimal point mandatory within that group, and I replaced[0-9]
with the more semantic\d
. Presumably you will want at least one digit, so I took the liberty to change*
to+
.