How do I remove all text to the right of the last "\", including the slash?
Also, how do I remove all text to the right of the 2nd to last slash?
For example, if I have 123\abc\dcc\xyz, how would i get 123\abc\dcc? how would i get 123\abc?
Thanks!
Solved! Go to Solution.
Hi,
If you have a multiple requirements for the number of \ to consider you may want to use the Text to Columns tool and then rebuild desired strings in a Formula. Otherwise, a formula tool will work.
See attached
Iain
And that formula would be what? The length of the characters is never the same.
@ivoller provides some good solutions however if you would like the number of splits to be dynamic then I would consider using the text to columns tool but using the 'split to rows' method.
You can then cross-tab your data back and you'll have n numbers of columns for each record. You can then concatenate them together as you wish.
"And that formula would be what? The length of the characters is never the same."
This is a formula that can be used in a Formula tool that will remove all the characters to the right of the last "\" character (including the "\" character). This will only work for the string segment that follow the last "\".
left([String],length([String])-(findstring(reversestring([String]),"\")+1))
The dynamic solutions that @ivoller and @BenMoss provided will be required to dive further into the string.
I would suggest using a Regular Expression -- either through the RegEx tool in the Parse toolbox or with the Regex_Replace function in the Formula tool.
In either case, the Regular Expression you could use would be:
(.*)\\.*
In the Formula tool this would look like:
Regex_Replace([Field],"(.*)\\.*","$1")
. = any character
* = 0 or more times
\\ is used because \ is a special character in RegEx, so to search for a 'literal' \, you have to 'escape' it, hence \\.
Because the first .* is in brackets, it is a 'marked group' (e.g. the part you want to keep). You return the marked group using the $1 syntax.
If you had 2 marked groups, you would use $1 and $2, which returns your matched string reading from left to right.
Thanks, I used this one below and it seemed to work, just had to do a little clean up.
(.*\\(.*?))
User | Count |
---|---|
18 | |
14 | |
13 | |
9 | |
8 |