- import java.util.regex.*;
- class RegexDemo
- {
- public static void main(String[] args)
- {
- // mySplit("abczzdefyyyghijwwwwwwwwkxxxxlmn","(.)\\1+");
- // telMatch("155843421611","1[358]\\d{9}");
- // myReplace("abczzdefyyyghijwwwwwwwwkxxxxlmn","(.)\\1+","$1");
- myRequire("get host hello dog match model reach","\\b[a-z]{4,}\\b");
- }
- public static void mySplit(String str,String reg)
- {
- String[] strs=str.split(reg);
- for(String s:strs)
- System.out.println(s);
- }
- public static void telMatch(String str,String reg)
- {
- System.out.println(str.matches(reg));
- }
- public static void myReplace(String str,String reg,String replacement)
- {
- str=str.replaceAll(reg,replacement);
- System.out.println(str);
- }
- public static void myRequire(String str,String reg)
- {
- Pattern p=Pattern.compile(reg);
- Matcher m=p.matcher(str);
- while(m.find())
- System.out.println(m.group());
- }
- }
复制代码
$代表什么? |
|