can someone please help with the expression to replace the spaces after the numbers with a dash using RegEx? this is going into a dynamic rename tool. thanks!
Example:
Before:
1234 4545 Building
334343 34345 Car
938 34343 Equipment
After:
1234-4545 - Building
334343-34345 - Car
938-34343 - Equipment
Solved! Go to Solution.
@Thableaus sorry missing one detail.
some of the text are two words so I only want the dashes in between the numbers and after the numbers. but not in between the words. thanks!
Before:
3934 3493 New Building
After
3934-3493 - New Building
If the pattern always consists of two sequences of digits (with whitespace in between), whitespace and anything else.
You can set this: REGEX_Replace([Field1], "(\d+)\s+(\d+)\s+(.*)", "$1-$2 - $3")
Cheers,
@Thableaus awesome, this works!
would you mind just explaining to me how the formula works? i have very basic understanding of regex. I know what d+ and s+ are but not sure how the groupings ( ) and $ works.
First, this website https://www.rexegg.com/ has a lot of good content on explaining how RegEx works.
But I will try to briefly explain groupings and $.
Captured groups are used to reference patterns. If you capture a part of your RegEX, you can use it later - best example is the Replace method.
$1, $2, $3 - refer exactly to these captured groups
They are like stored variables - in my example, I captured the digits ($1 and $2) and everything after the whitespace (.*)
Then in the Replace Method, I referenced them and replaced the \s+ for everything I needed (in this case, a dash).
Cheers,