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

    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);
            }
    }

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

原文地址:https://www.cnblogs.com/i80386/p/2620402.html