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

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -