Hello,
I need a regular expression that transforms expressions like this:
40304023
Into this:
40-304-023
Thank you.
Solved! Go to Solution.
So, close to what @mpennington present, I think you can combine these 2 formulas:
Like that:
Definitely along the same line as @marcusblackhill , just a slightly different variation, that is harder to read, but is should handle up to 15 digit numbers:
TrimLeft(
REGEX_Replace(
ReverseString(REGEX_Replace(
ReverseString((ToString([Number],0))),
"(\d{3})(\d{3})?(\d{3})?(\d{3})?(\d{3})?(\d{0,2})?","$1-$2-$3-$4-$5-$6")
),'-{2,}','-'),'-')
There's been a lot of great answers on this thread from @mpennington and @marcusblackhill
here's one more example of the magnificent value of regex in replace mode...
(\d{3}) in replace mode
$1- (replacement text)
and a few reverses and a trim...
Or trimleft(reversestring(REGEX_Replace(reversestring(tostring([Field1])), "(\d{3})", "$1-")),"-") for the one tool formula.
@apathetichell I really like your method, as it works regardless of the length. Great stuff!
Thanks! I love learning from all of these different approaches on these discussions!
Really like @apathetichell 's solution. It is more generic.
If it is specifically 3 characters, we could may be just use a thousand separator?
replace(tostring([Field],0,1),',','-')
Ravi