user415394
user415394

Reputation: 303

C# RegEx Match Pattern Exactly

I'm wanting to match a string exactly, for instance I have two expressions that I want to match independent of each other. Expressions are

/SignUpFor

/SignUpFor/ThankYou

The string "/SignUpFor" returns a match on the first expression which is correct; the string "/SignUpFor/ThankYou" returns a match on both.

How can I get "SignUpFor/ThankYou" just to match with the expression /SignUpFor/ThankYou.

The reason I'm not just using "==" is that I have other expressions such as /TheLovelyBlog/Entry/([0-9]+)

These expression are stored in a database.

Upvotes: 3

Views: 9303

Answers (3)

Dyppl
Dyppl

Reputation: 12381

Add ^ and $ in the beginning and in the end of your expressions

Upvotes: 4

Hans Kesting
Hans Kesting

Reputation: 39284

If you start a regex with ^, then the match must be from the start. End the regex with $ to signal that the match must be until the end.

Upvotes: 3

kmcc049
kmcc049

Reputation: 2801

put a ^ at the start and a $ at the end http://msdn.microsoft.com/en-us/library/h5181w5w.aspx

Upvotes: 13

Related Questions