正则表达式可匹配任何垂直空格 [英] Regular expression to match any vertical whitespace

查看:88
本文介绍了正则表达式可匹配任何垂直空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.NET是否存在与任何会导致多行的字符匹配的正则表达式模式,即任何垂直空格字符,例如perl regex对\v所做的操作?换句话说,有一种方法可以匹配\r(回车),\n(换行),\v(垂直选项卡)和\f(换页)以及Unicode字符(下一行),U+2028(行分隔符)和U+2029(段落分隔符)以及其他我不知道的其他字符可能会导致一行以上?

Is there a regex pattern for .NET that will match any character that will result in multiple lines, i.e. any vertical whitespace character, like perl regex does with \v? In other words, is there a way to match \r (carriage return), \n (line feed), \v (vertical tab), and \f (form feed) as well as the Unicode characters U+0085 (next line), U+2028 (line separator), and U+2029 (paragraph separator) and any other characters I'm not aware of that might result in more than one line?

我正在.NET中编写一些验证代码,如果用户提供的输入文本包含多行内容,则验证代码将失败.在大多数情况下,这意味着我只需要检查\r\n.但是,我知道还有许多其他垂直空白字符.

I'm writing some validation code in .NET that will fail if a user has provided input text that contains more than one line. In most cases, that means I just have to check for \r and \n. However, I know there is a multitude of other vertical whitespace characters.

我知道 .NET regex与perl regex有所不同,最重要的是.NET中的\v与"vertical tab"匹配,而在perl regex中与"vertical whitespace"匹配.

I know .NET regex differs from perl regex, most importantly in that \v in .NET matches "vertical tab" whereas it matches "vertical whitespace" in perl regex.

推荐答案

正如您所说,Perl字符类\v[\x0A-\x0D]匹配(换行符,垂直制表符,换页符和回车符(尽管我对此表示怀疑)除了非ASCII代码点[\x{2028}\x{2029}](行分隔符和段落分隔符)之外,CR是垂直空白).

As you say, the Perl character class \v matches [\x0A-\x0D] (linefeed, vertical tab, form feed and carriage-return (although I would dispute that CR is vertical white space)) in addition to the non-ASCII code points [\x{2028}\x{2029}] (line separator and paragraph separator).

您可以像这样在.NET中手动构建此字符类

You can hand-build this character class in .NET like this

[\u0A-\u0D\u2028\u2029]

这篇关于正则表达式可匹配任何垂直空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆