Alteryx Designer Desktop Discussions

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

regular expression - match string

raghadaf8
6 - Meteoroid

Hello !

 

I'm trying to get all the match strings in a text using regular expression.

 

for example the text is :

1. Title 1

paragraph 1

2. Title 2 

paragraph  

 

I need to get all the titles (1. Title 1 , 2. Title 2)

 

I have wrote this regular expression : (\d\. )(.)* 

and using this expression I'm getting the first title only. does anyone know how to get all the matches ?

 

12 REPLIES 12
ddiesel
13 - Pulsar
13 - Pulsar

Hi @raghadaf8!

 

Here's one way to do it:

(\d+\.\s\w+)

 

You can try it with the Tokenize option in the RegEx tool and split the result to rows.

 

Capture2.JPG

 

Hope this helps!

 

Deb

grazitti_sapna
17 - Castor

Hi @raghadaf8, this can also be done using the text-to-column tool.
I am not actually sure what your use case is so I have tried to solve it by considering 2 scenarios.

1. In case the data is in separate rows.

 

If the data representation is as below

grazitti_sapna_0-1655704538484.png

 

Then you can simply use a text-to-column tool to get the desired result.

grazitti_sapna_1-1655704584400.png

 

2. In case the data is in a single row.

grazitti_sapna_2-1655704610306.png


Then you can use the workflow attached in the screenshot.

grazitti_sapna_3-1655704641279.png


For scenario 2 regex might have a limitation and may result only in the first title. (Not sure though)

I hope this helps!

 

Thanks!

Sapna Gupta
Kurohits
10 - Fireball

Hi @raghadaf8 

 

Another way of doing this. Very easy method by using Matched Group option. For writing regular expressions and setting hand on it, you can use Rubular editor. You can easily practice and learn regular experssions there. 

 

Attaching the workflow for you reference. 

 

Kurohits_0-1655706910500.png

 

raghadaf8
6 - Meteoroid

hi ! thanks for the reply.

 

but that return the first word only, and i need it return the whole title

ddiesel
13 - Pulsar
13 - Pulsar

Hi again @raghadaf8!

 

You can give this one a try:

 

(\d+\.\s.+)

 

 \d+ = one or more digits

\. = period

\s = one space

.+ = one or more characters after the space (this will capture multi word titles)

ddiesel
13 - Pulsar
13 - Pulsar

@raghadaf8 

 

P.S. If that doesn't work, will you reply with a little more of your data (anonymized) so we can see the structure?

raghadaf8
6 - Meteoroid

that has returned the whole text starting from the first match, and all in one cell.

 

my data consist of numbered titles and each has a paragraph.

 

Example:

 

Document H 

 

1. Title text 1

paragraph of title text 1

 

2. Title text 2

Paragraph of title text 2

 

end of document H

Kurohits
10 - Fireball

Hi @raghadaf8 

 

Have you tried my solution? Also it would be better if you can share the sample data in excel exactly matching your requirement. It would help to understand better and provide the reliable solution. 

 

Thanks 

 

Rohit Gupta

ddiesel
13 - Pulsar
13 - Pulsar

Let's try this:

 

Capture.JPG

 

If this doesn't work, then please submit some sample data in excel as @Kurohits suggested so we can see where the breaks are in your data. We can all parse well! We are just guessing about your data structure :-)

Labels