How to use beginning and endline markers in regex for Java String?

后端 未结 5 2067
没有蜡笔的小新
没有蜡笔的小新 2021-01-04 19:51

Why doesn\'t the following change the text for me in Android?

String content = \"test\\n=test=\\ntest\";
content = content.replaceAll(\"^=(.+)=$\", \"

        
5条回答
  •  情深已故
    2021-01-04 20:27

    Okay, I think I have an answer... this seems to work:

    content = content.replaceAll("(?$1")
    

    Doesn't it?

    Edit: The above doesn't work, for some reason it copies the original text and places it after the substituted text... here's what finally did work:

    content = content.replaceAll("(?<=(\n|^))=(.+)=(?=(\n|$))", "$2");
    

提交回复
热议问题