Need regex expession to find certain words

Hii All
I have just started learning regex
& im stuck at a point

Actually i need to check 2 words are present in a string
im definitely using is match activity(BUT not getting the expressions)
please help

test String-

Isle of Man(COM),Estonian(EE),Danish(DK),European(EU),United Kingdom(UK),Bulgarian(BG),Schleswig-Holstein(DESH),Romanian(RO),Isle of Man(RUSO)

& we need find these 3 words-
isle of man(COM) , European(EU),

Please help

Thanks in advance :slight_smile:

2 Likes

Hi

There are two ways to find whether a word exists in a sentence or not

First is with CONTAINS method
Second is with ISMATCH method

As you want in IsMatch or Regex based expression

Use this in a if condition
System.Text.RegularExpressions.Regex.IsMatch(strinput.ToString,”(your word to be found)”)

To make it very simple
We can try with contains method

Like this in if activity

*Strinput.ToString.Contains(“your word”)

If true goes to THEN block or to ELSE

Cheers @Jiban_Stars

Hi @Jiban_Stars ,

If the Operation is to only Check if all/both the words exist in the String Input meaning a Boolean Output, then we can make use of the below Expression :

InputStr = "Isle of Man(COM),Estonian(EE),Danish(DK),European(EU),United Kingdom(UK),Bulgarian(BG),Schleswig-Holstein(DESH),Romanian(RO),Isle of Man(RUSO)"

StringToFindArray = {"isle of man(COM)","European(EU)"}

OutputBool = StringToFindArray.All(Function(x)InputStr.ToString.ToLower.Contains(x.ToLower))

StringToFindArray - Variable of Type String containing the words to Find.

InputStr - Variable of Type String, which contains the String in which we need to search words.

OutputBool - Variable of Type Boolean, which outputs to either a True or False.

Let us know if you need an Alternate solution of this doesn’t work.

Hi,

If you want to use IsMatch activity. the following will help you.
Please note we need to escape the string if use it as pattern because parentheses is special character in regex pattern.

Sequence.xaml (7.1 KB)

Regards,

Hey PaLaniyappan Thanks,
Infact I wanted to use “contains method” but I know only to match 1 word from the string…but here Im asking to match 2 or more words

So can you please tell me the updated expression for my requirement

Thanks

1 Like

image
Actually the string will be scrapped from a portal …so cannt add it to a array variable

So any other alternative than LinQ??

Thanks

Yeah still it can be done with CONTAINS for multiple words like this

YourArray.Contains(“yourString”.Split(" "c, stringsplitoption.none))

You can have this in IF activity and if true it goes to THEN block or ELSE block

Cheers @Jiban_Stars

1 Like

This can be still split to array of strings

Like this

If you have the above text obtained as a string variable named Strinput then use a assign activity like this

arr_str = Split(Strinput.ToString, Environment.NewLine)

Where arr_str is a array of string variable

Then you can use the above expression is shared to check between array and a string

Cheers @Jiban_Stars

1 Like

@Jiban_Stars , Although the data is Scrapped, meaning that is the Input String in the Example shown above, it would be assigned to InputStr.

StringToFindArray is the Array of String variable, which will contain the Strings that you need to search for in the InputStr, meaning the String values in StringToFindArray is already a decided value.

1 Like

Any further queries on this topic
@Jiban_Stars