How can I remove " - 2" from the end of the string only. Example:
ABS - 2 ---> ABS
AB - 2S ---> AB - 2S <-- Note this one was not replaced at " - 2" was not at the very end.
Thank you,
Zak
@zchotani Attaching the updated workflow for your use case. The Regex_Match formula will check whether the string ends with - 2 then it will remove the - 2 else write the same string
@zchotani One way of doing this
REGEX_Replace([String], '(.*)(\s\-\s\d+)(.*)', '$1$3')
Hi @zchotani
One way of doing this.
Need to better understand how to read regex. As in what in the formula make it such that it only replaces " - 2" at the end of the string and ignores the same character in leading or middle positions. I ended up using TrimRight....
Thank you @shankerV... TrimRight worked flawlessly!
Shanker,I am running into an issue with this formula:For example:
Its converting "Baton Rouge - Bricksome - 2" to ----> "Baton Rouge - Bricksome" which is correct
but its also incorrectly converting: "Novi - W 12" to --> "Novi - W 1"
We only want to trim out " - 2" from the strings if its at the trailing end of the string...
Any suggestions?
@binu_acs This worked flawlessly. If its not too much to ask, can you help me understand how the formula works... Specially what part looks for " - 2" at the end and how Match and replace formulas are working together?
@zchotani The formula Regex_Match([Field1], '.* \- 2$' - checks whether the given string ends with the string " - 2" , if that is true the regex_replace function split the string into two parts one with string up to the space before the - sign .
$-represents the end of the string.
2$ - means all string ends with 2
REGEX_Replace([Field1], '(.*)\s\- 2', '$1') here
.* will read the text up to the last string which is right to it. If you look at the above formula after the .* the next is \s(which is space) then \- (which is hyphen) then <space>2. so the .* will return anything before \s\- 2 ,
$1 represents the first group, here (.*) - is the group (Note: group is identified by whatever is in the bracket if you have two items in the bracket it will be $1 and $2)