Question

"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]*>", "" ));
}
Was it helpful?

Solution 2

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

But still looking for 1 line solution .

OTHER TIPS

       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)}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top