I would like a regex pattern to match all lines in a text file that has the follow pattern:
TcQuery {dynamic_content} Alias "{dynamic_content}" New
If the text file has these two lines:
//tcquery c_query alias "qrybklog" new <= This one shouldn´t be found because there is two backslashes before TcQuery.
tcquery c_query alias "qrybklog" new <= I want a pattern to match this line
I´ve tried this but both lines are matched:
var prw = System.IO.File.ReadAllText(@"d:\backlog.prw", Encoding.ASCII);
prw = "//TcQuery c_query Alias teste1 new";
prw = "\nTcQuery c_query Alias teste2 new";
prw = "\nTcQuery c_query Alias teste3 new";
prw = "\n//TcQuery c_query Alias teste4 new";
var regexTcQuery = new Regex("TcQuery+[ *]+[0-9a-zA-Z_]+[ *]+alias+[ *]+[0-9a-zA-Z_\"]+[ *]new$", RegexOptions.IgnoreCase);
var resultTcQuery = regexTcQuery.Matches(prw);
Use
singlelineandignorecaseoption with this regex(?<!\/\/)checks for//beforetcquery.*?is a lazily matches 0 to many characters.If you use.*then it would match the lasttcqureyskipping ibetweentcquerymatches\bis anon-wordboundary.This allows us to match separate words\smatches0tomanyspace which can be any of the[\n\r\t\f]If you want to get the c_query text you can do this