Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.

Alteryx Designer Desktop Discussions

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

RegEx issue with string

daophuongtrinh
8 - Asteroid

Hello everyone,

 

I'm having the string below:

 

XYZ.12.99]

XYZ.0]

XYZ.1]

XYZ.22]

 

I built two expression for RegEx tool which are:

\w{3}\.(.*[^\]])

 

\w{3}\.(\d.*[^\]])

 

The first expression matched all four strings, however when I run the second expression, the string "XYZ.0]" and "XYZ.1]" will result as Null.

 

I wonder why \d would come out as Null in this case.

 

If anyone have experience on this, please let me know.

 

Thank you very much,

Trinh

6 REPLIES 6
DiegoParker
10 - Fireball

Hi @daophuongtrinh 

 

I do believe is because (\d.*[^\]]) is marking two characters, the \d and the [ ] because your string only has one character then the rest is null as it can't match them.

 

Not 100% sure but that is my hunch.

 

Best,

Diego

VianneyM
Alteryx
Alteryx

hi @daophuongtrinh,

 

could you please let me know what you try to do? are you trying to match some strings?

 

what is the expected output?

 

Best,

Vianney

Best,
Vianney
daophuongtrinh
8 - Asteroid

Hi Vianney

 

My expected output is the number after "XYZ.", so I wanted to parse the digits after XYZ. and exclude the bracket (]) behind. In this example it would be 12.99 ; 0 ; 1 ; 22.

 

So I was wondering why this expression \w{3}\.(\d.*[^\]]) will result Null for some data such as "XYZ.0]" and "XYZ.1]"

 

Thank you

Trinh

daophuongtrinh
8 - Asteroid

Hi Diego,

 

Thank you for the explanation, but I'm sorry I don't really get what you mean. I wrote the expression \w{3}\.(\d.*[^\]]) in order to parse the number after "XYZ." but exclude the bracket (]) in the end of this string. It came out that [^\]] did exclude the bracket as I wanted, but I still don't get why \d.* will result in Null for "XYZ.0]" or ""XYZ.1]". 

 

Thank you for your support!

Trinh

fmvizcaino
17 - Castor
17 - Castor

Hi @daophuongtrinh ,

 

It took me a while to realized what was the problem with your regular expression.

(\d.*[^\]])

In this specific part of your expression, the problem is that you are demanding 2 characters, meaning that \d is a digit but [^\] is also anything other that a bracket.

 

So XYZ.0] won't be a match since 0 = \d but nothing is equal to [^\]

This expression will work for any other string with more that one digit

 

Best,

Fernando Vizcaino

 

daophuongtrinh
8 - Asteroid

Dear Fernando @fmvizcaino ,

 

Thank you very much for your explanation, which is very clear for me now. ^^

 

Best regards

Trinh

Labels