c# - Regex to get multiple filters -


i new regex , trying find files .cs,.json etc. but, getting 1 file extension i.e. 1 filter value.

code :

string ext = "json|cs|xml"; regex regex = new regex(@"<(compile|content|none) include=\""([^\""]+." + ext + @")\""( /)?>",regexoptions.ignorecase); match match = regex.match(line); //only takes json, not take cs or xml 

so, here matches json file.

can me regex.

short answer: need add bracket around include ext variable, parser knows match of options.

currently have going match character not including double quote , string json or string cs or xml. adding brackets (as below) tell parser match character not including double quote , of extension provide.

replace

<(compile|content|none) include=\""([^\""]+." + ext + @")\""( /)?> 

with

<(compile|content|none) include=\""([^\""]+.(" + ext + @"))\""( /)?> 

ps. find expresso useful in debugging regular expressions. not affiliated, been using quite number of years.


Comments