say i have a string as follows and i want to get what is between the
tags
String t = "<title> My First Page </title>";
String[] title2 = t.split(".+");
for(String s2 : title2)
outString += s2;
im pretty sure using the split method is the way to go but i cant
figure out how to set up the regex
hiwa - 05 Nov 2005 01:54 GMT
> using the split method is the way to go
Is it? I don't think so.
Try this:
--------------------------------------------------------------------------
public class RegxTest{
public static void main(String[] args){
String s1 = "<title lang=\"en\"> My First Page </title>";
String s2 = "<title>[foofoo]barbar</title>";
String s3 = "<title>(barbar)foofoo</TITLE>";
String regex = "(?i)(<title.*?>)(.+?)(</title>)";
System.out.println(s1.replaceAll(regex, "$2"));
System.out.println(s2.replaceAll(regex, "$2"));
System.out.println(s3.replaceAll(regex, "$2"));
}
}
-------------------------------------------------------------------
Roedy Green - 05 Nov 2005 08:50 GMT
>String t = "<title> My First Page </title>";
>String[] title2 = t.split(".+");
[quoted text clipped - 3 lines]
>im pretty sure using the split method is the way to go but i cant
>figure out how to set up the regex
your splitter is the string <title> or </title>
so for a first cut you might try "<title>|</title>"
But < is a reserved character , so I quote it, and > as well for
symmetry:
"\\<title\\>|\\</title\\>"
Remember to trim you strings and throw out "".
Another approach that will help ignore more stuff is to write finder
regex, then possibly a matcher regex on what you found.
See http://mindprod.com/jgloss/regex.html

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.