i want to know how to get the string from group of string
String j = "<a ............> hai</a>";
i want to get the string of tag of
<a ...> ... </a>
thanks and advance
i want to know how to get the string from group of string
String j = "<a ............> hai</a>";
i want to get the string of tag of
<a ...> ... </a>
thanks and advance
I'd use an XML parser for that and extract the attributes in question.
I agree with Bozho. If you need to do this on a regular basis, an XML or HTML Parser would be much less error prone.
For a quick and dirty approach, you can use the Regex
(href|src)="[^"]*"
Make sure to escape all these quotes when trying that.
I hate regex, I would have done it this way..
str = str.substring(str.indexOf("href="));
str = str.substring(0, str.indexOf("\"", 5); //'href=' is 5 chars
//str = str.substring(0, str.indexOf(" "); //this is more readable I think
Do the same for src=
Note, you will get href=
as part of the string as well, how to prevent that is left as an exercise. lol. (HINT: change 0
in the second line to ...)