Comparing a String to a list of Strings including wildcards

Hi All!

I’m having difficulty with a scenario, hoping you could help!

I have a list of strings which are acceptable eg: This Is A String 1 , This Is A String 2, This Is A String 3.
And I am comparing a string I have found and if it’s on this list I want to ignore and move on.

My issue is that the use case also wants wildcards in this list of acceptable string and then I want to compare my string against these also

eg: This Is A String 1, This Is A String 2, * Is A String *.

So for example if the string I am comparing to this list is That Is A String 4, I want this to match also. Basically i want to search this list for exact matches (which I have done already) but now I also want to account for these wildcards of acceptable markets too.

Having difficulty arranging an effective regex?

Many Thanks!

Hey!

It’s my bad… Could you please provide some input and expected output data?

So that will give you the solution

Regards,
NaNi

1 Like

Hi @Kyleb91 ,

If the String that you are comparing contains just Is A String is that valid or does it need to have some words/characters at the beginning and at the end also.

1 Like

Hey Man So that will be a string in the list and it will have words either side of this, so if the string I am comparing to this is for example “Team A Is A String Team B”, so as this has “Is A String” in it, I would like to ignore this.

@Kyleb91 ,

In that case, I don’t think a Regex would be required, We could go ahead with Contains method.

yourStringToCompare.ToLower.Contains("is a string")

If it needs to be exact case match, we could go ahead without any case transition like below :

yourStringToCompare.Contains("Is A String")

Do you think would work for your case ?

1 Like

Hi,

This can be done by the following steps

  1. For each and pass the list
    2 take a if condition item.Contains (string variable)
  2. Then block use continue
  3. else block if want add string variable to list use add to collections activity

Try this method

1 Like

Thanks man, I have tried this, yes, but my solution has many different versions of this in a list of strings so am hoping to build out a regex or find a better way of comparing to the list without individually specifying each one if that makes sense.

@Kyleb91 ,
Maybe we can separate the two lists, one containing the strings which should be a exact match, the other list containing the wildcard match.

exactMatchList.Any(Function(x)x.Equals(yourStringToCompare))              //Returns True if exact string is present in the list
wildCardsList.Any(Function(x)System.Text.RegularExpressions.Regex.IsMatch(yourStringToCompare,x))                         //Returns True if it matches any one of the values in wild card list

Considering wildCardList is a Array of String variable, which contains values already containing the wildcards/regex expression

wildCardList = {".*Is A String.*"}

image

1 Like

Thanks man this is great, getting there… although I am unsure if this is testing accurately for me the wildcardList expression. So in this I need to use the string from the list with it’s included wildcard to see if my string matches. I have tested this but the output is still showing a correct match even if i delete this from the list. I will spin up a xaml for clarity :slight_smile:

Main.xaml (11.8 KB)

I am getting a match here, but interestingly when I remove “.*First Tryscorer For Their Team” from the list, the If statement errors…

@Kyleb91 , You would need to correct the wildcards, In Regex it is not * it is .*.

image

Maybe some more explanations :

1 Like

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