pythonpyqt5qregexp

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

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