1
"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]*>", "" ));
}
bpbhat77
  • 529
  • 1
  • 6
  • 19
  • And again... [here](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454). – Mena May 14 '14 at 10:08

2 Answers2

1
       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)}
TheLostMind
  • 35,966
  • 12
  • 68
  • 104
  • Updated the question :) "TEST STARTaTEST END"; – bpbhat77 May 14 '14 at 10:12
  • Not working for me :( String text = "TEST aEND"; String text1 = text.replaceAll("*.",""); String text2 = text.replaceAll("\"",""); System.out.println(text1+text2); – bpbhat77 May 14 '14 at 10:35
0
text = (text.replaceAll( "(?i)(<a[^>]*?\\stestexpression\\s*)=\"", "" ));
        return text.replaceAll("}\"\\shref.+</a>", "}");

But still looking for 1 line solution .

bpbhat77
  • 529
  • 1
  • 6
  • 19