Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

removing text to the right of a character

bb213
8 - Asteroid

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!

7 REPLIES 7
ivoller
12 - Quasar

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

bb213
8 - Asteroid

And that formula would be what?  The length of the characters is never the same. 

ivoller
12 - Quasar

forgot attachment

BenMoss
ACE Emeritus
ACE Emeritus

@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.

 

 

CharlieS
17 - Castor
17 - Castor

"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.

tom_montpool
12 - Quasar

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.

 

bb213
8 - Asteroid

Thanks, I used this one below and it seemed to work, just had to do a little clean up. 

(.*\\(.*?))
Labels