正则表达式\p {Punct}错过了java中的unicode标点符号

编程入门 行业动态 更新时间:2024-10-15 00:28:06
本文介绍了正则表达式\p {Punct}错过了java中的unicode标点符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我写了一个小测试来证明

I wrote a little test to demonstrate

@Test public void missingPunctuationRegex() { Pattern punct = Patternpile("[\\p{Punct}]"); Matcher m = punct.matcher("'"); assertTrue("ascii puctuation", m.find()); m = punct.matcher("‘"); assertTrue("unicode puctuation", m.find()); }

第一个断言通过,第二个失败。您可能不得不眯着眼睛看它,但那是左单引号( U + 2018 )并且应该作为标点符号覆盖。据我所知。

The first assert passes, and the second one fails. You may have to squint to see it, but that is the 'LEFT SINGLE QUOTATION MARK' (U+2018) and should be covered as a punctuation as far as I can tell.

我如何匹配Java正则表达式中的所有标点符号?

How would I match ALL punctuations in Java regular expressions?

推荐答案

你可以使用 UNICODE_CHARACTER_CLASS 标记为 \ p {Punct} 匹配所有Unicode标点符号。

You can use the UNICODE_CHARACTER_CLASS flag to make \p{Punct} match all Unicode punctuation.

更多推荐

正则表达式\p {Punct}错过了java中的unicode标点符号

本文发布于:2023-10-08 15:11:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472993.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标点符号   正则表达式   java   Punct   unicode

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!