使用正则表达式匹配除三个之外的 Unicode 控制字符

发布于 2024-07-26 07:56:13 字数 151 浏览 3 评论 0原文

我需要一个正则表达式,它匹配除回车符 (0x0d)、换行符 (0x0a) 和制表符 (0x09) 之外的所有 Unicode 控制字符。 目前,我的正则表达式如下所示:

/\p{C}/u

我现在只需要定义这三个异常。

I would need to get a Regular Expression, which matches all Unicode control characters except for carriage return (0x0d), line feed (0x0a) and tabulator (0x09). Currently, my Regular Expression looks like this:

/\p{C}/u

I just need to define these three exceptions now.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夜空下最亮的亮点 2024-08-02 07:56:13

我认为您可以在这里使用否定前瞻,并结合字符类。

/(?![\x{000d}\x{000a}\x{0009}])\p{C}/u

其作用是使用否定前瞻来断言该字符不是字符类中指定的字符之一。 然后它再次遍历该字符以将其与任何控制字符相匹配。

我使用 perl 语法来指定单个 unicode 点。

关于lookarounds的更多讨论此处

(请注意,这还没有经过测试,但我认为这个概念是正确的。)

I think you can use a negative lookahead here, combined with character classes.

/(?![\x{000d}\x{000a}\x{0009}])\p{C}/u

What this does is use a negative lookahead to assert that the character is not one of those specified in the character class. Then it traverses the character again to match it with any control character.

I used the perl syntax for specifying single unicode points.

More discussion on lookarounds here

(Note that this has not been tested, but I think the concept is correct.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文