java - Regex to get rid of content after the first ">" -
regex rid of content after first ">" in string below. , putting whatever there after first ">" in string .
eg:
string input = <img alt="" src="http://abchdfgjd.com/-430.jpg" width="650" height="430" /> have seen <a href="http://www.funnyordie.com/between_two_ferns" target="_blank">between 2 ferns</a>?
desired output:
ans1 = <img alt="" src="http://abchdfgjd.com/-430.jpg" width="650" height="430" /> ans2 = have seen <a href="http://www.funnyordie.com/between_two_ferns" target="_blank">between 2 ferns</a>?
can me ?
unless misunderstand question, should (using indexof)
public static void main(string[] args) throws ioexception { string input = "<img alt=\"\" src=\"http://abchdfgjd.com/justin-bieber-ferns-650-430.jpg\" " + "width=\"650\" height=\"430\" /> have seen <a href=\"http://www.funnyordie.com/between_two_ferns\" " + "target=\"_blank\">between 2 ferns</a>?"; int pos = input.indexof(">"); string ans1 = input; string ans2 = ""; if (pos > -1) { ans1 = input.substring(0, pos + 1); ans2 = input.substring(pos + 2); } system.out.println("ans1: " + ans1); system.out.println("ans2: " + ans2); }
output is
ans1: <img alt="" src="http://abchdfgjd.com/justin-bieber-ferns-650-430.jpg" width="650" height="430" /> ans2: have seen <a href="http://www.funnyordie.com/between_two_ferns" target="_blank">between 2 ferns</a>?
Comments
Post a Comment