How to match the new numbers with commas?

by Vadi

Back to Mechanic's Corner.

Vadi2011-11-18 06:20:38
The new numbers with commas are awesome, but your triggers that use (\\d+) to match and capture a number won't work. Instead, use

(+)

And you're all set again!

For the sake of completeness, (+) will work just as well.
Ssaliss2011-11-18 10:01:46
That wouldn't cover spaces though, would it? Personally I'd choose the pattern + instead, and prune it of leading and trailing spaces afterwards (I assume there is such a function in LUA? Never really used it).
Vadi2011-11-18 20:30:09
There are no spaces in these numbers. To match the spaces before and after, you'd just insert them into the pattern as-is.
Ssaliss2011-11-18 21:10:56
You can config the numbers to be broken by commas or spaces, or neither though. CONFIG NUMBERS!

EDIT:
CONFIG NUMBERS:
Numbers allows you to declare your preference for formatting large numbers. With comma separation they will be shown as 1,000,000. With space separation, they will be shown as 1 000 000.
Your current setting is: 1,000,000.
Unknown2011-11-19 04:01:51
(+) will match numbers with spaces, but it will also match any space before it, so you need to be specific with the pattern you're using.

(\\d+\\d) will work for being less specific, it tells the pattern to start with a digit, and anything after that digit can either be more digits or a space, and it will match that way until it gets to the end, which says it must end in a digit (this is so it doesn't capture the space after the number too)

I'm not any good with regular expressions, there is probably a more elegant way.
Rivius2011-11-19 14:38:01
The "less specific" above example won't work.

Try:

(\\d(?:\\d+)*)+

Untested, but should work for each config.
Unknown2011-11-20 00:48:48
Rivius:

The "less specific" above example won't work.

Try:

(\\d(?:\\d+)*)+

Untested, but should work for each config.


I don't know why you say it wont work. I test everything I post before posting it, and it worked just fine.

Your example is cool. I like seeing more examples since I'm terrible at reading manuals. I tested it and it works for commas and spaces, but not for unformatted (none).
Rivius2011-11-20 08:59:03
Linelmarsith:


I don't know why you say it wont work. I test everything I post before posting it, and it worked just fine.

Your example is cool. I like seeing more examples since I'm terrible at reading manuals. I tested it and it works for commas and spaces, but not for unformatted (none).

Ah, well it seems to pick up multiple spaces and the second \\d prevents it from working on single digit numbers.

My example should work for unformatted numbers though...I'll revise it later if I remember :P It's likely horribly wrong as well.

edit: does this work better?

(\\d+(?:\\d+)*)
Unknown2011-11-20 23:49:42
Alright, I tried your new pattern and it does match all 3 configurations! It also works for small numbers.