Could someone give me the regex pattern and replacement pattern to replace blank thousands separators with commas? That is to say, 15 789 489 with 15,789,489.
Thanks.
Could someone give me the regex pattern and replacement pattern to replace blank thousands separators with commas? That is to say, 15 789 489 with 15,789,489.
Thanks.
Is this a search & replace operation or something else?
Are the numbers always like that or could there be these:
1 234 567 678
1 234 567
1 234
21 234 567 678
12 234 567
11 234
131 234 567 678
211 234 567
981 234
Or more?
Paul Filkin | RWS Group
________________________
Design your own training!
You've done the courses and still need to go a little further, or still not clear?
Tell us what you need in our Community Solutions Hub
Is this a search & replace operation or something else?
Are the numbers always like that or could there be these:
1 234 567 678
1 234 567
1 234
21 234 567 678
12 234 567
11 234
131 234 567 678
211 234 567
981 234
Or more?
Paul Filkin | RWS Group
________________________
Design your own training!
You've done the courses and still need to go a little further, or still not clear?
Tell us what you need in our Community Solutions Hub
Yes, it is search and replace, and it could be for any length of number like the examples you give.
At a very simple level you might get away with this:
(\d)\s(\d)
$1,$2
Paul Filkin | RWS Group
________________________
Design your own training!
You've done the courses and still need to go a little further, or still not clear?
Tell us what you need in our Community Solutions Hub
It doesn't seem to be working for me. For example for the number 145 125 789 489 Regex Match Autosuggest Provider is providing just 145,125
I asked you if this was a search and replace and you said yes. It will not achieve what you're after with the Regex Match AutoSuggest Provider. I thought you were letting Studio do it's thing and needed to run a search and replace afterwards.
To do what you want in the regex autosuggest provider I think you'll need to create multiple rules... maybe something like this:
\b(\d{1,3})\s(\d{1,3})\s(\d{1,3})\s(\d{1,3})\b
$1,$2,$3,$4
\b(\d{1,3})\s(\d{1,3})\s(\d{1,3})\b
$1,$2,$3
\b(\d{1,3})\s(\d{1,3})\b
$1,$2
Maybe someone else has a clever way of doing this in one... would love to know what this would be myself!
Paul Filkin | RWS Group
________________________
Design your own training!
You've done the courses and still need to go a little further, or still not clear?
Tell us what you need in our Community Solutions Hub
When I think about it, what I wanted would not really save me any time. Hitting ctrl+, and then Enter will give me the correct number in the target segment, and it is exactly the same number of keystrokes as hitting 2 and then Enter using Regext Match. Still, thanks for looking into it for me.
This is an interesting problem that should be easy to solve!
The best approach I can suggest is hardly clever, more "brute force" with 2 generalised regexes
regex 1: \b(\d{1,3})(\s(\d{3}))?(\s(\d{3}))?(\s(\d{3}))?\b
replace string: $1,$3,$5,$7
This handles numbers up to 10**12
The following regex cleans up the superfluous commas
regex 2: ((\d)*(,\d)*),*()
replace string: $1$4
sampleNumbers =
(
1 234 567 678
1 234 567
1 234
21 234 567 678
12 234 567
11 234
131 234 567 678
211 234 567
981 234
)
Loop, Parse, sampleNumbers, `n, `r
myResults .= RegExReplace(RegExReplace(A_LoopField, "\s+"), "(?<=\d)(?=(\d{3})+$)", ",") "`n"
MsgBox % myResults
Return
OR
I wanted to suggest a solution with "native" regex that does not allow program functions and loops.
yes, you are quite right.
I just wrote what I wanted to write (above code is AutoHotkey).
I am not interested in "Regex Match Autosuggest Provider" (what's that ?).
I, again, just wrote my Autosuggest Provider
What I am interested in is "get things done", nothing else.
Regards