System.Text.RegularExpressions.Regex.IsMatch problem

hey everyone,

I have a simple word comparing.

System.Text.RegularExpressions.Regex.IsMatch(description.ToString,“keyword”,System.Text.RegularExpressions.RegexOptions.IgnoreCase)

I check whether the “description” string variable holds a certain keyword.
Now my question is can I use wildcard like “report* sheet” so it will return true if the description is “reported sheet”. Or is there anyway i can make it work.

Thank you.

Hi,

Now my question is can I use wildcard like “report* sheet” so it will return true if the description is “reported sheet”.

Yes, it returns true, however * does not mean wildcard in regex. For example,it also returns true if input string is “repor sheet”.
Can you try the following expression?

 System.Text.RegularExpressions.Regex.IsMatch(description.ToString,"report.*sheet",System.Text.RegularExpressions.RegexOptions.IgnoreCase)

Regards,

1 Like

worked like a charm. Thank you very much. So to use * like a wildcard we need to add . before it? How is the logic work.

1 Like

Hi,

How is the logic work.

* means zero or more occurrences of the preceding element.
. means any character except \n(LF).

So, .* behaves like wild card.

FYI, “report*” means repor and 0 or more t. For example repor and reportttt will be matched.

If you want to learn more detail of regex, please see regex learning site in the internet.

Regards,

1 Like

thank you.

1 Like

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