字符串正则表达式
.matches
.replaceFirst
.replaceAll
.split
\d:[0-9]
\w:[a-zA-Z0-9]
\W:[^\w]
\s:空白符(所有)
\S:非空白符
^(在开始位置表示开始位置,在[]中表示取反)
$(末尾位置)
?(一个或0个)
*(0或多次)
+(一次或多次)
{n}:n次
{n,}:至少n次
{n,m}:n-m次
[abc] a|b|c
@Test public void testPattern() throws Exception { //匹配 Pattern pattern = Pattern.compile("HE",Pattern.CASE_INSENSITIVE); Matcher m = pattern.matcher("hello4 wowo3He"); while(m.find()){ System.out.println(m.group()); } //分割 Pattern pattern1 = Pattern.compile("\\s"); String[] str = pattern1.split("hello a yi"); System.out.println(Arrays.toString(str)); }
                    
                
                
            
        
浙公网安备 33010602011771号