Extract string between two strings in java

后端 未结 4 1255
不思量自难忘°
不思量自难忘° 2020-11-27 05:57

I try to get string between <%= and %>, here is my implementation:

String str = \"ZZZZL <%= dsn %> AFFF <%= AFG %>\";
Pattern pattern = Patter         


        
4条回答
  •  日久生厌
    2020-11-27 06:42

    I have answered this question here: https://stackoverflow.com/a/38238785/1773972

    Basically use

    StringUtils.substringBetween(str, "<%=", "%>");
    

    This requirs using "Apache commons lang" library: https://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.4

    This library has a lot of useful methods for working with string, you will really benefit from exploring this library in other areas of your java code !!!

提交回复
热议问题