Loading

6.正则表达式入门之选择匹配

?=、?<=、?!、?<! 的使用区别:

1. ?=

exp1(?=exp2):查找 exp2 前面的 exp1。
例子:

public static void main(String[] args) {
   
    String str="life is  a fuck _movie";
    //获得一个正则表达式对象
    Pattern p = Pattern.compile("life(?= is)");
    //使用正则表达式对象处理指定字符串,并获得结果对象
    Matcher m = p.matcher(str);
    //从正则表达式结果对象中获得信息
    while (true){
   
        if(m.find()) {
   
            System.out.print(m
posted @ 2021-12-19 13:01  文牧之  阅读(12)  评论(0)    收藏  举报  来源