.NET Framework Bookmark and Share   
 index > Regular Expressions > Converting simple wildcard user inputed text that into regex
 

Converting simple wildcard user inputed text that into regex

I have a Text box and the user can enter names like "*smith"

Where "john smith" and "thesmith" would qualify.

The regex is simple. But,does anybody have suggestions on how to interpret that into regex? are there any samples on the internet?

I searched and could not find any.

Nick

nick5454

You can replace the "*" with ".*", prepend with "^" and append "$":

string regex = "^" + textBox.Replace("*",".*") + "$";

To check for a match, use:

if (Regex.IsMatch(inputString, regex))

...

Philippe Leybaert

You can use google to search for other answers

Custom Search

More Threads

• How can I extract numbers only from a string
• How can i match this text with a regex?
• Regular Expression Hang
• need help parsing a paragraph bounded by
• Help with RegEx Seek-n-Find
• Sequential letters and numbers: "abc" "123"
• Match only two letters and not more
• Splitting string into groups
• Does .NET supoort Binary Regular Expression?
• Is Regex Fast Enough for you?