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

后端 未结 5 2055
没有蜡笔的小新
没有蜡笔的小新 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:45

    Your original regex works fine if you turn on multiline mode, using (?m):

    content = content.replaceAll("(?m)^=(.+)=$", "$1");
    

    Now ^ and $ do indeed match at line boundaries.

提交回复
热议问题