我正在尝试创建一个正则表达式以匹配包含CRLF的字符串。这是为了验证给定字符串中是否存在CRLF。
我正在使用:
Regex.IsMatch(allRead, "^the dog jumped\r\n$", RegexOptions.Singleline)
但是我没有取得任何成功。
Regex.IsMatch(allRead, "the dog jumped\\r\\n")
Regex.IsMatch(allRead, @"the dog jumped\r\n")
除非您期待allread
仅包含“然后狗跳了”,否则不需要使用^
-换句话说,除非您只想匹配字符串的开头(或者如果您使用RegexOptions.Multiline
,则匹配行的开头)
您也可能不需要使用$
,除非您想确保新行是字符串的结尾(或者如果您使用RegexOptions.Multiline
,则下一行为空白)
请按照以下方式尝试。
Regex.IsMatch(allRead, "^the dog jumped\r\n$", RegexOptions.Multiline)
这可能会对您有所帮助。
gd
fg
dfg
the dog jumped
the cat jumped
the dog jumped
the dog jumped
打开多行模式,尝试使用这个正则表达式...
^the dog jumped$