我正在使用RegEx on Java,这就是我遇到的问题。
我有一个简单的字符串,如
String sample1 = "word 231 sadas aslkjasf anything ORDER what whut ASC hello ORDER whatever."
我必须找到每个子字符串,直到两个ASC
之间最后一次出现ORDER
,并用字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"
答案 0 :(得分:1)
试试这个
s = s.replaceAll("(ORDER.*ASC)(?=.*?ORDER.*)", "QQQ");