K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Campbell Ritchie wrote:Have you searched for regular expressions for decimal numbers? You can find a ready‑made regex easily enough; if you go through the documentation for Scanner and Formatter, you will find regexes for numbers. You can then add plain simple - and ~ to them, or as alternatives. Remember that − is a meta‑character, so you should change it to "\\-". You can check here, but I think that ~ is not a meta‑character.
Menoux Mathieu wrote:
But the RegEx for decimal number is that, no ?
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
Menoux Mathieu wrote:Henry Wong, I don't find any way to do that without an optional whole number :/ So the only way is to do a second RegEx for this:
Menoux Mathieu wrote:
And it works ! So here are the solution to my question
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:Sometimes, it's best not to write a single, massive regex that covers every possible situation, but instead write several smaller ones - just like writing methods in a program.
I can't say if that would work in this specific situation, as I haven't spent much time deciphering your requirements, but it is something to consider.
I use alternance "|" instead of different matches, I think it's also clear and more simpler !Campbell Ritchie wrote:Fred means to match parts of the text, and put the regexes together to match the whole of your number.
Forget Steve. Look at this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|