Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to pass Philippine Currency in QRegExp?

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading