日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

java的lookingat_Java Matcher.lookingAt()部分匹配字符串

發布時間:2025/4/16 java 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java的lookingat_Java Matcher.lookingAt()部分匹配字符串 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

首頁?>?基礎教程?>?正則表達式?>?Matcher類

Java Matcher.lookingAt()部分匹配字符串

Matcher.lookingAt()對前面的字符串進行匹配,只有匹配到的字符串在最前面才返回true。

定義

public boolean lookingAt()

例子

實例一

Pattern p=Pattern.compile("\\d+");

Matcher m=p.matcher("22bb23");

m.lookingAt();//返回true,因為\d+匹配到了前面的22

Matcher m2=p.matcher("aa2223");

m2.lookingAt();//返回false,因為\d+不能匹配前面的aa

實例二

public static void main(String arg[]) {

String string = "123-34345-234-00";

Pattern pattern = Pattern.compile("\\d{3,5}");

Matcher matcher = pattern.matcher(string);

boolean result1 = matcher.matches();

System.out.println("result1=" + result1);

//重置匹配器。

matcher.reset();

//嘗試查找與該模式匹配的輸入序列的下一個子序列。

boolean result2 = matcher.find();

System.out.println("result2=" + result2);

boolean result3 = matcher.find();

System.out.println("result3=" + result3);

boolean result4 = matcher.find();

System.out.println("result4=" + result4);

boolean result5 = matcher.find();

System.out.println("result5=" + result5);

//嘗試將從區域開頭開始的輸入序列與該模式匹配。

boolean result6 = matcher.lookingAt();

System.out.println("result6=" + result6);

boolean result7 = matcher.lookingAt();

System.out.println("result7=" + result7);

boolean result8 = matcher.lookingAt();

System.out.println("result8=" + result8);

}

運行結果:

result1=false

result2=true

result3=true

result4=true

result5=false

result6=true

result7=true

result8=true

總結

lookingAt是部分匹配,總是從第一個字符進行匹配,匹配成功了不再繼續匹配,匹配失敗了,也不繼續匹配。

版權聲明:本文為JAVASCHOOL原創文章,未經本站允許不得轉載。

總結

以上是生活随笔為你收集整理的java的lookingat_Java Matcher.lookingAt()部分匹配字符串的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。