導航:首頁 > 編程語言 > java正則匹配img

java正則匹配img

發布時間:2023-06-10 17:53:59

java 正則表達式獲取下面的img中的屬性值

importjava.util.regex.Matcher;
importjava.util.regex.Pattern;

publicclassSpider
{
publicstaticvoidmain(String[]args)
{
Stringinput="<imgclass="entImg"k1="ZHA455544942terttte"k2=".png"label="FjYBs45643455xCbc234Me"src="h-p://73442dc.c344.20.34.clo4434ddn.com/Z4554520438534.png?e=6839&token=:3242346I342343SBr8mw="style="width:300px;height:300px;"/>";
Stringregex="(?i)(k1|k2|label|src)[="'\s]+([^"']*)(?=["'\s>]+)";
Patternpattern=Pattern.compile(regex);
Matchermatcher=pattern.matcher(input);
while(matcher.find())
{
System.out.println(matcher.group(1)+":"+matcher.group(2));
}
input=input.replaceAll("(?i)(src[="'\s]+)[^"']*(?=["'\s>]+)","$1\$hash\$");
System.out.println(input);
}
}

❷ 急 java里用正則替換掉img標簽的src里的內容

我覺得可以先用正則把先匹配出imgName = 「圖片名.gif」,回然後再替答換:

content = content.replaceAll("(.*?)src=\"(.*?)","$1src=\"../image/" + imgName);

❸ java正則表達式匹配img路徑

package table;

public class FileTester
{
public static void main ( String[] args )
{
String reg = "(src[\\=\\s\'\"]+)http\\:\\/\\/img\\.\\.com\\/hi\\/[^\'\"]+([\'\"])";
String url = "sdfsdf<img src='https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/hi/we.com' />sdf<img src='https://gss0.bdstatic.com/70cFsjip0QIZ8tyhnq/hi/we.com' />sf'";
url = url.replaceAll (reg, "$1$2");
System.out.println (url);
}
}

❹ java正則匹配字元串,下面給出的這段字元串,我想取出裡面的img 裡面的src路徑的內容,保存在一個數組裡面.

String bireinfo = "<IMG border=0 align=center src=/epbwebeditor/uploadfile/20140509103010830.jpg 300px; HEIGHT: 201px></SPAN></FONT><SPAN style=FONT-FAMILY: New FONT-SIZE: 10.5pt Roman?,?serif?; ?Times><IMG border=0 align=center src=/epbwebeditor/uploadfile/20140509103058264.jpg 300px; HEIGHT: 201px></SPAN><SPAN style=FONT-FAMILY: New FONT-SIZE: 10.5pt Roman?,?serif?; ?Times><IMG border=0 align=center src=/epbwebeditor/uploadfile/20140509103323797.jpg 300px; HEIGHT: 201px></SPAN></P>";
Pattern p = Pattern.compile("(?:src=\"?)(.*?)\"?\\s");
Matcher m = p.matcher(bireinfo);
String[] arr = new String[10];
int i = 0;
while(m.find()) {
arr[i] = m.group(1);
i++;
}

❺ 給一個網頁源碼 ,在java中用正則匹配如何將<img = "xxxxx" ,xxx> 這樣形式的所有標簽過濾掉 求解-_-

Stringhtml="";
//"."代表任意非換行的字元,".*"代表任意多個這樣的字元,後面跟個"?"表示最小匹配
//這里的回空格直接用空格表示,如答果不確定空格數量,最好用s代替空格
Patternpattern=Pattern.compile("<img=".*?",.*?>");
Matchermatcher=pattern.matcher(html);
while(matcher.find()){
//你的代碼,這里是輸出
System.out.println(matcher.group());
}

❻ Java正則表達式匹配出網頁圖片地址並替換掉

有點簡單了。。你網頁的圖片有什麼特徵沒有?是全部圖片都替換掉么?那樣你會崩潰的。那麼多小圖片logo、邊框什麼的至少會有個class啊什麼的特徵。如果僅僅是匹配所有網頁的圖片。
regex="(?i)<img[^>]*?src=\"([])\""
Pattern pa=Pattern.compile(regex);
Matcher ma=pa....(content);
while(ma.find()){
int index=ma.start(1);
int end=ma.end(1);
然後通過開始和結束來把字元串替換掉就好了,
}

❼ java正則表達式匹配img標簽並替換

publicstaticvoidmain(String[]args){

Stringxx="hdjksahdjkshjkhkjdhsakj<imgsrc="/ee/ads/blll/1.0.0/img/defineform.png"/>dsadsajkdas";

Stringregex="src="/ee/ads/blll/1.0.0/img/defineform.png"";
xx=xx.replaceAll(regex,"tttt");
System.out.println(xx);
}

❽ java 正則表達式用於給<img src=「」 alt="" >添加style屬性即為

packagetest;

publicclassJButtonTest
{
publicstaticvoidmain(String[]args)
{
Stringregex="(?i)(\<img)([^\>]+\>)";
Stringinput="<imgsrc=""alt="">";
input=input.replaceAll(regex,"$1style="width:500px;height:400px;"$2");
System.out.println(input);
}
}

❾ java正則表達式匹配文本,獲得鏈接

Stringstr="<imgid="aimg_H5lCH"onclick="zoom(this,this.src,0,0,0)"class="zoom"file="http://www.m2tx.com/images/2006/07/30/ms_431yuria041.jpg"onmouseover="img_onmouseoverfunc(this)"lazyloadthumb="1"border="0"alt="">>";
Stringpattern="file=".+jpg"";
//創建Pattern對象
Patternr=Pattern.compile(pattern);
//現在創建matcher對象
Matcherm=r.matcher(str);
if(m.find()){
Stringfile=m.group();
System.out.println(file.substring(6,file.length()-1));
}

閱讀全文

與java正則匹配img相關的資料

熱點內容
dede工具 瀏覽:507
5g網盟app怎麼下載 瀏覽:486
微信備份老是連接中斷 瀏覽:886
出台多少份文件 瀏覽:380
鞋子怎麼搭配衣服的app 瀏覽:755
文件名使用的通配符的符號是什麼 瀏覽:916
lol分卷文件損壞怎麼辦 瀏覽:276
6分管車螺紋怎麼編程 瀏覽:732
海口農商銀行信用卡app是什麼 瀏覽:770
win10任務欄文件夾我的電腦 瀏覽:14
安卓nba2k18 瀏覽:776
文件夾密碼怎麼修改密碼 瀏覽:271
蘋果數據中心用什麼伺服器 瀏覽:769
省內圓通快遞寄文件夾需要多少錢 瀏覽:740
iphone程序加密 瀏覽:884
win10文件夾調整文件行高 瀏覽:681
創意手繪教程 瀏覽:754
微信刪除帳號信息 瀏覽:596
mysql操作類文件 瀏覽:649
繞過xp密碼 瀏覽:158

友情鏈接