Alex Rivera | Logout

How to match begin or end of a line using C#'s Regex?

Asked 2011-07-06T12:05:25.680
28

I'm trying to match this expression:

^COMA1TA2000,.*$

with this text:

# Qualquer linha iniciada por # será ignorada
# Caracteres que não podem serem usados na nomenclatura das copiadoras ou modelos.
# & < > " '
COMA1TA2000,ta-2000,hd,COMB1
#COMA2TA2000,ta-2000,hd,COMB2
#COMA3TA2000,ta-2000,hd,COMB3

I can do that using Notepad++, but I can't with the C# Regex class.

content = sr.ReadToEnd();
string pattern =  "^COMA1TA2000,.*$";
if(Regex.IsMatch(content, pattern))
System.Windows.Forms.MessageBox.Show("Test");

What am I missing?

Edit
Report

1 Answer

16

Or set multiline option in regex (?m): (?m)^COMA1TA2000,.*$

answered 2011-07-06T12:22:48.147

Your Answer