How to indicate "AND" in a Regex

Hello,

I have a strings like this “The boy is strong” Or “The Strong tower was built by the boy”.
I need a regex patter that returns true whenever the string contains “boy” & “Strong”.

Best Regards

Hi @MasterOfLogic

I don’t think so we have AND operation in REGEX expression.

You can try with IF activity to check the string.

Have a look on the XAML file

StringContains.xaml (8.3 KB)

Regards
Gokul

1 Like

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.IsMatch(yourString,"^(?=.*boy)(?=.*strong).*$")

Regards,

1 Like

Hello @MasterOfLogic ,

Instead of regex match pattern you can also go with string.contains functionality to check this :

InputString = “The boy is strong"
Bool_Var = InputString.Contains(“boy”) And InputString.Contains(“Strong”)

This will give you the required result.

Regards,
Rohith

1 Like

Hi @MasterOfLogic ,

Could you Check if the Below Works :

^(?=.*\bStrong\b)(?=.*\bboy\b).*$

1 Like

Hello, I had used the following condition:

((System.Text.RegularExpressions.Regex.Match(str1.toUpper(), “BOY”).Value.toString <> “”) And
(System.Text.RegularExpressions.Regex.Match(str1.toUpper(), “STRONG”).Value.toString <> “”))

str1 is the text sentence to be searched for the 2 keys.
You can try different combinations of keys, like “STRONG” / “WEAK”, a.s.o.
Can be a little confusing, because the resulting Match value is not a String.
As you can see, the pattern string was converted to uppercase in this condition.
This is because in a sentence the words can begin with a capital letter.

Best regards, Adrian

This condition also worked to me:

System.Text.RegularExpressions.Regex.IsMatch(str1, “^((?=.*boy)((?=.*strong)|(?=.*Strong)))”)

Best regards, Adrian

1 Like

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