简体   繁体   English

C#RegEx匹配模式完全正确

[英]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; 字符串“/ SignUpFor”返回第一个正确表达式的匹配项; the string "/SignUpFor/ThankYou" returns a match on both. 字符串“/ SignUpFor / ThankYou”返回两者的匹配。

How can I get "SignUpFor/ThankYou" just to match with the expression /SignUpFor/ThankYou . 如何才能将“SignUpFor / ThankYou”与表达式/SignUpFor/ThankYou

The reason I'm not just using "==" is that I have other expressions such as /TheLovelyBlog/Entry/([0-9]+) 我不只是使用“==”的原因是我有其他表达式,如/TheLovelyBlog/Entry/([0-9]+)

These expression are stored in a database. 这些表达式存储在数据库中。

把^放在开头,把$放到最后http://msdn.microsoft.com/en-us/library/h5181w5w.aspx

在表达式的开头和结尾添加^$

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. $结束正则表达式,表示匹配必须一直到结束。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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