Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22544

C# Dynamic Regular Expression where comparison string might have predictable variations

$
0
0

Trying to dynamically match a string against a list of strings to find a match, but the input might have slight variations.

Here's an example:

List of titles;

Trying to match "BK III" in list of titles, but in the title, it could be represented as "BKIII" or "BK-III"

If I do something like the following, it works well when there's an exact match, but I'm trying to account for the slight variation

string escapedModelNumber = Regex.Escape(product.ToLower());string pattern = $@"\b{escapedModelNumber}\b";              foreach (string s in titles){    if (Regex.IsMatch(s, pattern, RegexOptions.IgnoreCase))    {        return p;    }}

Viewing all articles
Browse latest Browse all 22544

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>