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
Yoichi
(Yoichi)
March 2, 2023, 1:48am
2
Hi,
How about the following pattern?
^Travel Associates
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
Yoichi
(Yoichi)
March 2, 2023, 2:10am
4
HI,
For better understanding your requirement, can you share your worksheet?
Regards,
@Yoichi I have this so far but can’t figure out the Travel Associates part
\W*((?i)All Brands|ONLINE|CORPORATE(?-i))\W*
Yoichi
(Yoichi)
March 2, 2023, 2:23am
7
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
Yoichi:
(?<=-\s+)[\w ]+")
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.
Yoichi
(Yoichi)
March 2, 2023, 2:57am
9
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,
Yoichi
(Yoichi)
March 2, 2023, 3:10am
10
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
system
(system)
Closed
March 5, 2023, 3:27am
12
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.