简体   繁体   English

正则表达式在C#中匹配\\ n

[英]regex matches \n in c#

i need to escape the special characters, so i have checked the regex options like as below, new Regex(@"^[\\w@.-]*$",RegexOptions.Compiled); 我需要转义特殊字符,因此我已经检查了如下正则表达式选项,即new Regex(@"^[\\w@.-]*$",RegexOptions.Compiled); it's working fine for all special character except \\n so how can i check it for all special character. 对于\\ n以外的所有特殊字符,它都工作正常,因此我如何检查所有特殊字符。

Use a negative lookahead assertion: 使用否定的超前断言:

^[\\w@.-]*(?!\\n)$

Demo . 演示

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

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