I need to trim anything past the - which then contains numbers
For example
'Town - Building - 125475' = Trimmed to 'Town - Building'
Tried a few REGRX_Replace but can only get the numbers to replace leaving the -
Thanks
Solved! Go to Solution.
Try Regex parse with the following:
(.*)\s-\s\d+
Works for your example but let me know if you run into any issues.
@tf05 use the formula REGEX_Replace([String],’(.*)\-.+’,’$1’)
@tf05 ,
Let's take a look at the RegEx question and apply a little explanation. Your challenge is to use the RegEx_Replace() function and perform a trim (deletion of target data from the source) against your field.
We don't know how you intend to use the result, so let's start there. If you are UPDATING the current field, you'll want to use either a FORMULA tool or the RegEx tool. I'm partial to the FORMULA tool for beginners. You also could be FILTERING rows based upon the presence of one of these field values. In this case you might not care about saving the result. If you're creating a new field/variable, you'll likely use the FORMULA tool (again you could use RegEx tool).
The challenge that you were having when trying this on your own were with the RegEx_Replace function. Let's start there:
$ is the "End of a String". If you want to assure yourself that the replacement is at the end of the field, you'll likely want one of these.
\s is a "WHITESPACE" character. It actually matches any space, tab or newline character. If you only want to match a space, you can simply type a space character. this makes it a little bit harder to read.
- is a "DASH" character. It is NOT necessary to place a slash \ in front of it. When used as a token to indicate a range of characters [0123456789] or [0-9] it does take on a different meaning.
\d is any numeric digit.
+ is a quantifier. It means that you have 1 or more of whatever token precedes it.
So if you write:
Regex_Replace([Field1],"spaceDASHspaceOneOrManyDigitsENDofString",'')
you will look for the expression (yet to be written in RegEx) with nothing (quote quote).
Regex_Replace([Field1],"\s-\s\d+$",'')
Here's another formula:
Regex_Replace([Field1],"\b.-.\d+$",'')
You can use https://regex101.com/ to explain what it does.
The 2nd expression is more expensive than the first expression. It does however teach a concept that is very useful to learn.
Cheers,
Mark