Regex Multiple condition

I am looking for a regex code to extract value.

I am using each row datatable activity and I want to extract following string based on the value in a column.

All from AU Domestic - All Brands (excl Travel Associates)

Travel Associates from AU Domestic - Travel Associates

Online from AU Domestic - ONLINE

CORPORATE from AU Domestic - CORPORATE/FCM

I only want to extract Travel Associates it’s not after excl.

Thanks in Advance

Hi,

How about the following pattern?

^Travel Associates

image

Regards,

thanks @Yoichi My condition is I am doing each row in a datatable and depend on the column value I want to extract specific word. I need one expression to tackle all

All Brands if the column value is AU Domestic - All Brands (excl Travel Associates)

Travel Associates if the column value is AU Domestic - Travel Associates

Online if the column value is AU Domestic - ONLINE

CORPORATE if the column value is AU Domestic - CORPORATE/FCM

HI,

For better understanding your requirement, can you share your worksheet?

Regards,

@Yoichi here you go

regex_Dummy.xlsx (9.8 KB)

@Yoichi I have this so far but can’t figure out the Travel Associates part

\W*((?i)All Brands|ONLINE|CORPORATE(?-i))\W*

HI,

Can you try the following expression, if “-” always exists before these keywords?

System.Text.RegularExpressions.Regex.Match(CurrentRow("Details").ToString,"(?<=-\s+)[\w ]+").Value

Sample20230302-2L.zip (10.4 KB)

Regards,

1 Like

thanks it’s working. If the data format changes in the future it will create an issue that’s why I was looking for specific words.

Hi,

All right. How about the following?

System.Text.RegularExpressions.Regex.Match(CurrentRow("Details").ToString,"(?<=^|\W\s*)(All Brands|Travel Associates|ONLINE|CORPORATE)(?=\s*\W|$)",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value

This returns keyword if non-word character exists before and after it.

Sample20230302-2Lv2.zip (10.5 KB)

Regards,

HI,

Sorry, I had a mistake. The following is better.

System.Text.RegularExpressions.Regex.Match(CurrentRow("Details").ToString,"(?<=^\s*|[^\w\s]\s*)(All Brands|Travel Associates|ONLINE|CORPORATE)(?=\s*[^\w\s]|\s*$)",System.Text.RegularExpressions.RegexOptions.IgnoreCase).Value

Sample20230302-2Lv3.zip (10.3 KB)

Regards,

1 Like

thanks @Yoichi

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.