regex - I think my regular expression pattern in C# is incorrect -


i'm checking see if regular expression matches string. have filename looks somename_somthing.txt , want match somename_*.txt, code failing when try pass should match. here code.

string pattern = "somename_*.txt"; regex r = new regex(pattern, regexoptions.ignorecase); using (zipfile zipfile = zipfile.read(fullpath)) {    foreach (zipentry e in zipfile)    {        match m = r.match("somename_something.txt");        if (!m.success)        {            throw new filenotfoundexception("a filename format: " + pattern + " not found.");         }     } } 

the asterisk matching underscore , throwing off.

try:

somename_(\w+).txt 

the (\w+) here match group @ location.

you can see match here: https://regex101.com/r/qs8wa5/1


Comments

Popular posts from this blog

java - Solr query version issue: Invalid version or the data in not in 'javabin' format -

Hard vs. Soft Water: What's The Difference?

The Ten Most Livable Cities In The World