문제

"TEST START<a class=\"fic.test\" testexpression=\"LTRIM(a)\" testognlexpression=\"${LTRIM(a)}\" href=\"\">a</a>TEST END";

I am having anchor tag in String variable. i want to retrieve only value of attr testognlexpression.

Abouve string should be replaced with this

TEST START ${LTRIM(a)} TEST END

how can i retrieve or replace?

my code looks like

String text = "START<a class=\"fic.test\" testexpression=\"LTRIM(a)\" testognlexpression=\"${LTRIM(a)}\" href=\"\">a</a>END";
    System.out.println(text.replaceAll( "</?a[^>testognlexpression]*>", "" ));
}
도움이 되었습니까?

해결책 2

text = (text.replaceAll( "(?i)(<a[^>]*?\\stestexpression\\s*)=\"", "" ));
        return text.replaceAll("}\"\\shref.+</a>", "}");

But still looking for 1 line solution .

다른 팁

       public static void main(String []args){
       String text = "<a class=\"fic.test\" testexpression=\"LTRIM(a)\" testognlexpression=\"${LTRIM(a)}\" href=\"\">a</a>";
       String val=text.replaceAll( ".*testognlexpression=", "" );
       System.out.println(val.split("\\s+")[0].replaceAll("\"",""));
       }

OP :

${LTRIM(a)}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top