How to match array of strings variable with String variable using Regular Expression

Hi Everyone,
How to match array of strings variable with string variable using regular expressions.
Below is Example

arr_Strings arrs={“RFi”,“RFq”,“RFx”}
String str = “AbbVie_OR_20190724_RFIFinal2”

Thanks in advance :slight_smile:

1 Like

@harsha1123

Use ForEach loop to iterate that array and compare with the string whether its matching or not.

1 Like

Hi @lakshman

Use For each item in arrs

if(Str.ToString.equals(item))

Thanks
Ashwin S

As for the example above, You may also have to convert the string to All Upper case or All Lower case and have the array compare strings accordingly (either all Upper or all Lower) id using Strings or use a RegEx with IgnoreCase.

here you go with a xaml
hope its resolved
arrregex.zip (2.1 KB)

Cheers @harsha1123

is it working buddy
kindly let know for any queries or clarification

@harsha1123

Hey @Palaniyappan,hope you doin great,
great solution buddy but is there any solution where we we can solve this without for each loop. Because i have to download the files which does not matches any of the strings in the array variable.

1 Like

Yah of course we can by mentioning the array element index like with same expression, remove the loop but instead of item.ToString mention as
arr_strings(0).ToString
Similarly three assign activities with index number of element changing
Like this with same expression but instead of item.Tostring
arr_strings(1).ToString
arr_strings(2).ToString

Cheers @harsha1123

@Palaniyappan, Haanji, I can do that but I’m looking for long run bot, i mean in future the strings in array might increase so I’m using config file to read the probabilities of the names inside string array.
so for now I’m doing like this:

  1. In config file i have stored the data in the following way RFi,RFq,RFx
  2. Bot will split the data based on delimiter “,”
  3. Then I’m using this method RF_probabilities.Any(Function(x) final_FileName.Contains(x))

but here is the problem it is identifying even if there is any name lke CURF,BRFUs.
so if there is any solution i would like to request any xaml file which solve this issue brilliantly.

Cheers @Palaniyappan

Any suggestions?

1 Like

If this array is going to get incremented it can be handled by that attached xaml itself in the previous comment
As we have used only for each loop to iterate through those string elements in that array
Even if that gets increased only the number of for each loop iteration gets increased and gets compared accordingly for each element in the array with the input string, which is what we want right

Cheers @harsha1123

@harsha1123

Make all RF_Probabilities values to Upper case and then use below code

RF_probabilities.contains(System.Text.RegularExpressions.Regex.Match(str_input,“[a-zA-Z]+(?=Final)”).ToString.ToUpper).tostring

So here is the solution after some investigation with my colleague without using for each loop
arrayOfString arr = RFx_Probablities.Any(Function(x) System.Text.RegularExpressions.Regex.IsMatch (final_FileName,“(”+x+“)(?!\w)”))

Thanks everyone for the support especially @Palaniyappan.

1 Like

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