bh_earth0
bh_earth0

Reputation: 2818

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""

enter image description here

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

enter image description here

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

Upvotes: 1

Views: 91

Answers (1)

Flynn1179
Flynn1179

Reputation: 12075

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.

Upvotes: 1

Related Questions