如何通过QREGEXP通过菲律宾货币?

发布于 2025-02-12 20:09:14 字数 196 浏览 0 评论 0原文

我目前正在研究正则是我的正则是:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愚人国度 2025-02-19 20:09:15

您应该通过更改\₱可选为[\₱] {0,1}

r"[\₱]{0,1}[0-9]*[.]{0,1}[0-9]{0,2}"

注意:我始终使用{0,1}语法,而不是{,1}确保下一个开发人员清楚其功能。

条件

  1. 可能从字符开始
  2. 数字必须具有小数点,
  3. 它无法检测到负数,
  4. 它在小数点

外部雷格克斯小提琴

之后将不会接受超过2个位置。 /1“ rel =“ nofollow noreferrer”> https://regex101.com/r/dbk1dq/1

You should make optional by changing \₱ to [\₱]{0,1}

r"[\₱]{0,1}[0-9]*[.]{0,1}[0-9]{0,2}"

Note: I always use {0,1} syntax and not {,1} to ensure the next developer is clear on what it does.

Conditions

  1. May or may not start with the character
  2. Number must have a decimal point
  3. It cannot detect negative numbers
  4. It will not accept more than 2 position after the decimal point

External Regex Fiddle

https://regex101.com/r/dBk1Dq/1

浅笑轻吟梦一曲 2025-02-19 20:09:14
r"₱?\d+(?:\.[0-9]{,2})?"

不需要符号之前的逃逸。我还使剩下的速度更加简洁,更快,因此引擎不需要通过使整个小数部分进行可选,但是该组中的小数点是强制性的,我更换了[0-9 ]带有更多语义\ d。大概您将需要至少一位数字,因此我将自由更改为* +

r"₱?\d+(?:\.[0-9]{,2})?"

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 +.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文