導航:首頁 > 編程語言 > java正則匹配並替換

java正則匹配並替換

發布時間:2022-03-11 17:39:47

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正則表達式,怎麼替換指定字元串為 指定字元+原字元串

String text = "ABCDE";
String regex = "([A-Z])";//這里的()表示保存匹配的結果
System.out.println(text.replaceAll(regex,"\\\\$1")); //$1取出保存的第1個

㈢ java正則表達式取值並保持格式替換

import java.util.regex.*;

public class Exam
{
public static void main(String[] args)
{
final String s="t1:\"1:0\",t2:\"2:0\",t3:\"2:1\",t4:\"2:2\"",d;
Pattern p=Pattern.compile("(\\d):(\\d)");
Matcher m=p.matcher(s);
// System.out.println(s);
d=m.replaceAll("s$1$2");
System.out.println(d);
}
}

㈣ java正則表達式 如何匹配 | 或者是如何替換 |

"1|2".replaceAll("\\|","a");

瀏覽器裡面快速驗證:
javascript:alert("1|2".replace(/\|/,"a"));

㈤ JAVA正則表達式替換字元串問題

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

publicclassTestRegex
{
publicstaticvoidmain(String[]args)
{
Stringregex="第[0-9]*條";
Stringstr="第9條,數據錯誤,錯誤信息,第jjj哦條哦條我的條件如何?第221條xx";
Patternpat=Pattern.compile(regex);
Matchermatcher=pat.matcher(str);
while(matcher.find()){
Stringtemp=str.substring(matcher.start(),matcher.end());
str=str.replaceAll(temp,temp.substring(0,temp.lastIndexOf("條"))+"行");
}
System.out.println(str);
}
}

㈥ java正則表達式替換一段字元串

Java正則表達式 .*(from.*)$ 替換成 select count(*) $1

完整的Java替換程序如下

publicclassAA{
publicstaticvoidmain(String[]args){
Strings="Selectafromxxxa"+"wherea.id=:id";
Stringregex=".*(from.*)$";
Stringresult=s.replaceAll(regex,"selectcount(*)$1");
System.out.println(result);
}
}

運行結果
selectcount(*)fromxxxawherea.id=:id
因為我不知道TbItem.class.getName()方法返回的表名,所以用xxx代替.
你可以用Strings="Selectafrom"+TbItem.class.getName()+"a"+"wherea.id=:id";沒問題不用改.

㈦ java正則表達式查找替換字元串怎麼寫

我給你一個把數字前面的0去掉(中間和尾部的0保留)的Java正則表達式替換字元串的程序.

publicclassTest{
publicstaticvoidmain(String[]args){
Strings="000120440";
System.out.println(s.replaceAll("^[0]+",""));
}
}

運行結果

120440

㈧ java想替換字元,正則表達式該怎麼寫

/**
* 在String對象上添加trim方法
*/
function String.prototype.trim()
{
return this.replace(/(^\s*)|(\s*$)/g,"");
}

㈨ java正則表達式怎麼一個個替換匹配的內容

Stringa="我是f_static_000的f_static_001aaaf_static_001";
//正則根據自己需要修改,replaceAll可以使用正則的捕獲組功能,$n引用第n個捕獲組
/**
replaceAll(regExp,replacement);第一個參數是正則字元串,第二個是替換內容
正則裡面有捕獲(正則裡面用小括弧捕獲)和引用的功能
*/
a=a.replaceAll("(f_static_\d+)","#[face/png/$1.png]#");

閱讀全文

與java正則匹配並替換相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:62
Windows常用c編譯器 瀏覽:778
關於改善國家網路安全的行政命令 瀏覽:833
安卓如何下載網易荒野pc服 瀏覽:654
javainetaddress 瀏覽:104
蘋果4s固件下載完了怎麼解壓 瀏覽:1003
命令zpa 瀏覽:286
python編譯器小程序 瀏覽:945
在app上看視頻怎麼光線調暗 瀏覽:540
可以中文解壓的解壓軟體 瀏覽:593
安卓卸載組件應用怎麼安裝 瀏覽:913
使用面向對象編程的方式 瀏覽:339
程序員項目經理的年終總結範文 瀏覽:929
內衣的加密設計用來幹嘛的 瀏覽:433
淮安數據加密 瀏覽:292
魔高一丈指標源碼 瀏覽:982
松下php研究所 瀏覽:168
c回調java 瀏覽:401
夢幻端游長安地圖互通源碼 瀏覽:746
電腦本地文件如何上傳伺服器 瀏覽:313