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

REGEX and padding

vishwakar
8 - Asteroid

Hi

 

i Need to extract the below information from this tag

 

<zone h='50000' id='8' name='Sheet 2' show-title='true' w='84000' x='0' y='50000' />

 

I have tried the below regex expression

 

^[ ]*<zone h='(.*?)' id='(.*?)' name='(.*?)' show-title='(.*?)' w='(.*?)' x='(.*?)' y='(.*?)' />$

 

Whats wrong with the above regex expression, It returns null.

 

 

Expecting it to return vaues

returnvalues.PNG

 

Thanks

Karthik

 

Uploaded the sample workflow.

17 REPLIES 17
jdunkerley79
ACE Emeritus
ACE Emeritus

At a guess there is a trailing extra space in the input. I would suggest you make the regex a little more loose:

 

<zone\s*h='([^']*)'\s*id='([^']*)'\s*name='([^']*)'\s*show-title='([^']*)'\s*w='([^']*)'\s*x='([^']*)'\s*y='([^']*)'\s*/>

 

This will not be as sensitive to white space.

I prefer [^']* over the .*? as we know looking for next '

vishwakar
8 - Asteroid

Hi 

 

It did not help , still returns null

 

Thanks

Karthik

MikeA
Alteryx
Alteryx

Hi @vishwakar,

 

An alternative to extracting the data within the apostrphies does not use regex at all. Instead you can use a Text to Columns tool and split to rows using an apostrophy as the delimiter which results in the data being "flipped" vertically to rows anywhere there was an apostrophy:

Capture.JPG

 

Once the data is in that format, you can use a Multi Row forumula tool with the following expression: IF Contains([Field1], "=") THEN [Row+1:Field1] ELSE Null() ENDIF. This looks for a cell of data that contains an equals sign, and when it finds one of those cells, it will populate a new field with the value just below it:

Capture.JPG

 

You can then filter the new field based on NULL values to get a final results of:

Capture.JPG

 

This option is a bit more dynamic as you won't have to account for all of the "name='value'" bits in your data. Attached is an example workflow of the above process using your sample data

 

vishwakar
8 - Asteroid

Thanks for your solution , I need Regex as part of the work flow which is easier rather than converting to text to columns and appending makes its complex.

 

Thanks

Karthik

JohnJPS
15 - Aurora

Hi Karthik,

 

Since that's very XML-ish input, you might consider using the XML parser.  I pushed the input through it and the default settings parsed out the attributes perfectly. (See attached).

Federica_FF
11 - Bolide

What method are you using with the regex tool?

 

Because your original expression perfectly works to me with the parse method.

jdunkerley79
ACE Emeritus
ACE Emeritus

I would suggest going to the formula tool and parsing each field as its own then is not sensitive to order or missing fields, e.g. for h:

REGEX_Replace([Field1],"<zone.*?\sh='([^']*)'.*","$1")

Have attached a REGEX parse (with the first regex I suggested) and a formula demo

 

JohnJPS
15 - Aurora

To echo what Frederica said, I've added an example of a working "Regex Parse" tool to my workflow... this uses your original expression to "Parse" the data successfully.  Either that or the XML Parse appear to work very nicely with minimal configuration on your part.

 

vishwakar
8 - Asteroid

Thanks all for the prompt response and help

 

Updating the workflow sample on what I am doing. Need to extract the zone values of contaiing name as suggested earlier.

 

Thanks

Karthik

Labels