简体   繁体   中英

regex.matches notmatching

im trying to do this for 5 hours im desperate im gonna get mad. please helpme.

var start   =  new  List<string>( ) {"Report", "Audit"  , "Committee" } ;
string expresss= start[0] + @"(.*?)\n{0,1}(.*?)" + start[1] + @"(.*)$";
MatchCollection matches = Regex.Matches(text, "(?im)"+ expresss );

this code fails to find ""REPORT OF THE AUDIT COMMITEE""

在此处输入图片说明

but here wit sublime text3's regex ican find it .

在此处输入图片说明

please help me to find ""REPORT OF THE AUDIT COMMITEE"" via c# regex code. thanks.

Looks like it's both the fact that it's case sensitive, and you're not matching a regex across multiple lines (thanks to @stribizhev for spotting that).

Use:

MatchCollection matches = Regex.Matches(text, "(?im)"+ expresss,
  RegexOptions.Multiline | RegexOptions.IgnoreCase );

I can't tell from the context, but it might also be worth considering whether using RegexOptions.CultureInvariant is also appropriate.

EDIT: Ok, I had no idea C# could use (?im) for case + multi-line matching. In that case, not sure how this worked for you, if (?im) didn't. I just took the options off my test, leaving the (?im) on and it did match.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM