[英]Replace last occurrence of word between 2 words with RegEx
我正在使用Java上的RegEx,這就是我要堅持的地方。
我有一個簡單的字符串
String sample1 = "word 231 sadas aslkjasf anything ORDER what whut ASC hello ORDER whatever."
我必須找到每個子字符串,直到兩個ORDER
之間最后一次出現ASC
為止,並用單詞QQQ
替換它們。
這里有些例子:
String sample1 = "word 231 sadas aslkjasf anything ORDER what whut ASC hello ORDER whatever.";
String result1 = "word 231 sadas aslkjasf anything QQQ hello ORDER whatever.";
// replaced "ORDER what whut ASC"
String sample2 = "word 111 sadas anything ORDER what whut yeap ASC nope ASC maybe ORDER yeah.";
String result2 = "word 111 sadas anything QQQ maybe ORDER yeah.";
// replaced "ORDER what whut yeap ASC nope ASC"
嘗試這個
s = s.replaceAll("(ORDER.*ASC)(?=.*?ORDER.*)", "QQQ");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.