⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 例子8.txt

📁 这是一本java基础教程 对新手上路有很大帮助
💻 TXT
字号:
import java.util.regex.*;
public class Example6_8{
    public static void main(String args[ ]){
        Pattern p;                             	//模式对象
        Matcher m;                            	//匹配对象
        String s1="0A1A2A3A4A5A6A7A8A9";  	//待匹配的字符序列
        p=Pattern.compile("\\dA\\d");              	//用模式"\\dA\\d"初始化模式对象
        m=p.matcher(s1);                       	//用待匹配字符序列初始化匹配对象
        while(m.find()){
           String str=m.group();
           System.out.print("从"+m.start()+"到"+m.end()+"匹配模式子序列:");
           System.out.println(str);
        } 
        String temp=m.replaceAll("***");
        System.out.println(temp);
        System.out.println(s1);
        m=p.matcher("9A00A3");                    	//重新初始化匹配对象
        if(m.matches()){
           String str=m.group();
           System.out.println(str);
        } 
        else{
           System.out.println("不完全匹配");
        }
        if(m.lookingAt()){
           String str=m.group();
           System.out.println(str);
        }   
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -