Hello,I need a regular expression that transforms expressions like this:40304023Into this:40-304-023Thank you.
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.
I think this should work, given your example.
ReverseString(REGEX_Replace( ReverseString(ToString([Field1])), "(\d{3})(\d{3})(\d{2})","$1-$2-$3"))
Hi @BautistaC888 !
Always have that pattern?( lenght, only numbers)
If yes, you don't need regex, can use string formulas for it, like:
left([field1],2)+"-"+substring([field1],3,3)+"-"+right([field1],3)
Hope that helps!
I should note that my solution above is overly complicated, if you just have 8 digits every time, but the format allows you to expand on the RegEx to deal with other scenarios. If it is always 8 digits, you could essentially work it left to right to accomplish the same thing:
Regex_Replace(ToString([Field1]),'(\d{2})(\d{3})(\d{2})','$1-$2-$3')
No, the patterns are different.
@apathetichell I really like your method, as it works regardless of the length. Great stuff!