现在的位置: 首页 > 综合 > 正文

.net 匹配所有标点符号 java 匹配所有标点符号

2013年04月29日 ⁄ 综合 ⁄ 共 468字 ⁄ 字号 评论关闭
    static void Main(string[] args)
        {
            Regex regex=new Regex("\\p{P}");
            String str = " ;。、,!\"#$%&'*+,-./:;<=>?@[\\]^_`{|}~";
            MatchCollection mc=regex.Matches(str);
            if (mc != null && mc.Count != 0) 
            {
                foreach (Match m in mc)
                {
                    Console.Write(m.Value);
                }
            }
            Console.ReadLine();
        }

    public static void main(String[] args) {
            
            Pattern pattern=Pattern.compile("\\pP");
            Matcher match=pattern.matcher(" ;。、,!\"#$%&'*+,-./:;<=>?@[\\]^_`{|}~");
            while(match.find()){
                String p=match.group();
                System.out.print(p);
            }
    }

;。、,!"#%&'*,-./:;?@[\]_{}

抱歉!评论已关闭.