Reputation: 37
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
Upvotes: -1
Views: 53
Reputation: 198476
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 +
.
Upvotes: 0
Reputation: 489
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.
₱
https://regex101.com/r/dBk1Dq/1
Upvotes: 0