第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定

正則表達(dá)式^和\A的區(qū)別 $和\Z的區(qū)別

^和\A的區(qū)別

$和\Z的區(qū)別




正在回答

2 回答

public?static?void?main(String[]?args)?{?
????????String?matcherStr?=?"This?is?the?first?Java";
????????matcherStr?+=?"\nAnd";
????????matcherStr?+=?"\nThis?is?the?second?Python";
????????Matcher?matcher?=?Pattern.compile("Java$",?Pattern.MULTILINE).matcher(matcherStr);
????????
????????int?i=0;
????????while(matcher.find()){
???????????i++;
????????}
????????System.out.println(i);
}

There is one match (i=1) for Java in the first line. This is mutiline, so the whole matcherStr is something like:

This is the first Java

And

This is the second Python


public?static?void?main(String[]?args)?{?
????????String?matcherStr?=?"This?is?the?first?Java";
????????matcherStr?+=?"\nAnd";
????????matcherStr?+=?"\nThis?is?the?second?Java";
????????Matcher?matcher?=?Pattern.compile("Java$",?Pattern.MULTILINE).matcher(matcherStr);
????????
????????int?i=0;
????????while(matcher.find()){
???????????i++;
????????}
????????System.out.println(i);
}

There are two matchs (i=2) for Java in the first line. This is mutiline, so the whole matcherStr is something like:

This is the first Java

And

This is the second Java


public?static?void?main(String[]?args)?{?
????????String?matcherStr?=?"This?is?the?first?Java";
????????matcherStr?+=?"\nAnd";
????????matcherStr?+=?"\nThis?is?the?second?Python";
????????Matcher?matcher?=?Pattern.compile("Java$").matcher(matcherStr);
????????
????????int?i=0;
????????while(matcher.find()){
???????????i++;
????????}
????????System.out.println(i);
}

There is no match?(i=0) for Java. This is not mutiline, so the whole matcherStr is something like:

This is the first Java\nAnd\nThis is the second Python


public?static?void?main(String[]?args)?{?
????????String?matcherStr?=?"This?is?the?first?Java";
????????matcherStr?+=?"\nAnd";
????????matcherStr?+=?"\nThis?is?the?second?Java";
????????Matcher?matcher?=?Pattern.compile("Java\\Z",?Pattern.MULTILINE).matcher(matcherStr);
????????
????????int?i=0;
????????while(matcher.find()){
???????????i++;
????????}
????????System.out.println(i);
}

There is one match?(i=1) for Java with multiline.? The same as without multiline.

In this case: If Pattern.compile("Java$",?Pattern.MULTILINE), there are two matches.


public?static?void?main(String[]?args)?{?
????????String?matcherStr?=?"This?is?the?first?Java";
????????matcherStr?+=?"\nAnd";
????????matcherStr?+=?"\nThis?is?the?second?Java";
????????Matcher?matcher?=?Pattern.compile("Java\\Z").matcher(matcherStr);
????????
????????int?i=0;
????????while(matcher.find()){
???????????i++;
????????}
????????System.out.println(i);
}

There is one match?(i=1) for Java without multiline.


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

cc在哪 提問者

不錯的例子
2016-11-01 回復(fù) 有任何疑惑可以回復(fù)我~

^?
指定匹配必須出現(xiàn)在字符串的開頭或行的開頭。

\A?
指定匹配必須出現(xiàn)在字符串的開頭(忽略?Multiline?選項(xiàng))。


$?
指定匹配必須出現(xiàn)在以下位置:字符串結(jié)尾、字符串結(jié)尾的?\n?之前或行的結(jié)尾。

\Z?
指定匹配必須出現(xiàn)在字符串的結(jié)尾或字符串結(jié)尾的?\n?之前(忽略?Multiline?選項(xiàng))。?



1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

cc在哪 提問者

就是說^和$能匹配多行,\A和\Z不行嗎
2016-10-28 回復(fù) 有任何疑惑可以回復(fù)我~
#2

慕粉3863858

能就個(gè)例子嗎?我在字符串中加\n效果也是一樣的
2016-10-30 回復(fù) 有任何疑惑可以回復(fù)我~
#3

慕粉3936973 回復(fù) cc在哪 提問者

\A和\Z設(shè)置或者不設(shè)置多行匹配,效果是一樣的。參照我下面的最后兩個(gè)例子。
2016-10-31 回復(fù) 有任何疑惑可以回復(fù)我~
#4

慕粉3936973 回復(fù) 慕粉3863858

請參照下面示例。
2016-10-31 回復(fù) 有任何疑惑可以回復(fù)我~
#5

慕粉3936973 回復(fù) 慕粉3863858

請參照下面示例。
2016-10-31 回復(fù) 有任何疑惑可以回復(fù)我~
查看2條回復(fù)

舉報(bào)

0/150
提交
取消
python正則表達(dá)式
  • 參與學(xué)習(xí)       80571    人
  • 解答問題       176    個(gè)

如何使用正則處理文本,帶你對python正則有個(gè)全面了解

進(jìn)入課程

正則表達(dá)式^和\A的區(qū)別 $和\Z的區(qū)別

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號