Alteryx Designer Desktop Discussions

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

A little help with RegEx (special characters)

kwieto
8 - Asteroid

Hi, I need a bit help with RegEx: I want it to match specific string (let's say: ABC), but only if it is at the end of the word. According to the syntax, I should use "\>" to mark end of the word so the whole string will be ABC\>

And basically it works, but only if the text I am looking for doesn't contain special characters, like dot or parenthesis. If the string is ABC. or ABC) , writing ABC.\> or ABC)\> won't match the looked string.

As I understood, for special characters I should use "escape mark" (\), but writing ABC\.\> or ABC\)\> doesn't work either.

10 REPLIES 10
ShankerV
17 - Castor

Hi @kwieto 

 

Can you please share some sample input and expected output.

 

Many thanks

Shanker V

Qiu
20 - Arcturus
20 - Arcturus

@kwieto 
Only adding  ABC\.\> or ABC\)\>  means you MUST have the dot or parenthesis.
Maybe we can try something like this.
and we dont really need the \> to indicate it is end of word.

Regex1.PNG

flying008
14 - Magnetar

Hi, @kwieto 

 

ABC[.)]*?$

flying008_0-1685345823545.png

 

kwieto
8 - Asteroid

Sure. Let's consider three cases:

 

1this is sample string with strings
2this is sample string. With strings
3(this is sample string) with strings

 

I want to capture text "string." in the second row without matching "string" and "string)" from row 1 and 2, or be able to capture text "string)" from row 3 without matching "string" or "string." from row 1 or 2. And of course without word "strings" in each case.
For this example let's say I want to replace this string with the word "ABC".

So for the looked value "string." I should receive this output:

1this is sample string with strings
2this is sample ABC With strings
3(this is sample string) with strings


and for the looked value of "string)" I should have that output:

1this is sample string with strings
2this is sample string. With strings
3(this is sample ABC with strings

 

 

Both cases are separate, so there will be one formula for each case separately.

kwieto
8 - Asteroid

@flying008 - with your formula it won't match the looked string if it is in the middle of the longer string (i.e. fdsdfgdABC 4679fsdfs), as the dollar sign means end of the line. Or am I wrong?

kwieto
8 - Asteroid

@Qiu - I see I was not precise 😥
I don't want to capture all three cases, but only one of them. So if I look for ABC. , the formula should not match ABC or ABC) . And if I look for ABC) , then ABC and ABC. should be skipped


So this:

 

Only adding  ABC\.\> or ABC\)\>  means you MUST have the dot or parenthesis.

is correct.

Qiu
20 - Arcturus
20 - Arcturus

@kwieto 
Thank you for the feedback. Then I guess it makes thinks easier?

Regex2.PNG

kwieto
8 - Asteroid

Thanks, this works!
I still wonder why the syntax ABC\> works, but ABC\.\> doesn't.

 

By the way, do you have idea how to put output text in quotes, maybe?

For example, if I want to put the whole output from your formula ( '$1ABC$2' ) in quotes, writing: '\"$1ABC$2\"' won't work :(

 

flying008
14 - Magnetar

Hi, @kwieto 

 

As your said, why did you must need use regex expression ?

 

flying008_0-1685348316963.png

 

Labels