Bring your best ideas to the AI Use Case Contest! Enter to win 40 hours of expert engineering support and bring your vision to life using the powerful combination of Alteryx + AI. Learn more now, or go straight to the submission form.
Start Free Trial

Alteryx Designer Desktop Discussions

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

Expression for removing the line within cell with remaining some lines

Boontida
7 - Meteor

Dear all, 

 

I have the data as shown in Text column which contains the text with multilines.

I would like to set the formula for obtainind the result as shown in Target column by removing the line for the line starting with the text a-z and remaining the line for the line starting with the number 0-9.

 

However, the expression: REGEX_Replace([_CurrentField_], '\n', ' ')  will remove all lines within the cell.

 

Please kindly suggest me about the expression to remove the line within the cell with condition (remaining the line for the line starting with number). 

 

Boontida_0-1663039997287.png

 

Thank you so much in advance.

Best regards,

 

9 REPLIES 9
Luke_C
17 - Castor
17 - Castor

Hi @Boontida 

 

I'm pretty sure regex doesn't support using \n. Try this: 

 

 

Replace([_CurrentField_], '
','')

 

Boontida
7 - Meteor

Dear @Luke_C 

 

Thank you so much for you help.

 

I try by using your expression and I have still found that all lines in the cell will be removed. 

 

Boontida_1-1663044294040.png

 

I would like to maintain some lines within the cell (the line starting with number 0-9 is still the new line) and remove only the line starting with the text a-z.   

 

For example,

 

Good morning How are you
I'm fine thank
you

1 aa bb cc
aaaaa

2 bbbccc

 

To

 

Good morning How are you I'm fine thank you

1 aa bb cc aaaaa

2 bbbccc

 

 

Kindly suggest please.

 

 

 

grazitti_sapna
17 - Castor

@Boontida , Please try using the attached workflow and let me know if it helped

Sapna Gupta
flying008
15 - Aurora

Hi, @Boontida 

 

If only flow your example data, you can use the formula:

 

---> Please pay attention to copy the formula directly for use, do not edit it into one line.

 

Replace(REGEX_Replace(Replace([Text], "
", "|"), "\|[a-zA-Z][^0-9]+(?=\||$)", ""),"|","
")

 

 

录制_2022_09_13_13_56_39_877.gif

 

********

If it can help you , please mark it with a solution to share more.

Boontida
7 - Meteor

Dear @grazitti_sapna 

Thank you very much for your help.

 

However, I've still found some output data which removes all new line (as shown in record 1 of the picture below).

Boontida_0-1663156587969.png

 

Kindly suggest please if you have any solution. 

Thank you in advance

 

Boontida
7 - Meteor

Dear @flying008 

Thank you very much for your help.

 

However, some text in the output cell is deleted (as shown in record 1 of the picture below).

For example, my input contain the data as shown below

 

Input 

Good morning How are you
I'm fine thank
you

1 aabbcc
aaaaa

2 bbbccc

 

And the reult is found to be as follows.

 

Output

 

Good morning How are you
1 aabbcc
2 bbbccc

 

From the example, the text "I'm fine thank you" which should be shown in the same line of "Good morning How are you" is deleted.

 

Boontida_0-1663156935908.png

 

 

Kindly suggest please if you have any solution to fix this problem. 

Thank you in advance

Christina_H
14 - Magnetar

How about this one:

 

REGEX_Replace([Text], '\n([[:alpha:]])', ' $1')

 

Christina_H_1-1663166590569.png

 

flying008
15 - Aurora

Hi, @Boontida 

 

1- Jesus!  maybe now I finally get the result you want!

2- Please modify the formula to :

REGEX_Replace([Text], "\n(?=[a-zA-Z])", " ")

 

录制_2022_09_15_08_06_10_587.gif

 

************

Please mark this as the solution if it answers your question, it will help others to find solutions quicker.

Boontida
7 - Meteor

Thanks to you both @Christina_H  and @flying008 

Your expressions are great.

 

Thanks a lot again !

Labels
Top Solution Authors