简体   繁体   English

字符串的正则表达式以\\结尾

[英]Regular expression for a string ends with \

i am new for regular expression .i want to validate the path like this d:\\ or d:\\test\\ or d:\\test\\test\\ or d:\\test\\test\\test\\test\\ 我是正则表达式的新手。我想验证类似d:\\d:\\test\\d:\\test\\test\\d:\\test\\test\\test\\test\\的路径

it should always end with \\ 它应该总是以\\结尾

i tried this but does not work for my purpose ^([a-zA-Z]:)?(\\\\[a-zA-Z0-9_\\-]+)+\\\\? 我尝试了此操作,但对我的目的不起作用^([a-zA-Z]:)?(\\\\[a-zA-Z0-9_\\-]+)+\\\\?

这应该为您解决问题:

bool result = Regex.IsMatch(yourstring, @"\\$");

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

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