Sorry, I was at work and we were fixing to leave so I was rushed to
type that up.
Here is an example of the input:
path:\string1\string2\...\stringn:<a letter><some more paramaters that
may contain a :>
Now, the only string I want to get from that input is stringn. I can
gurantee that there will only ever be once occurance of something that
looks like \[a-zA-Z]: THe problem is I cannot get any of the
expressions I write for the splite string function to work. The one I
currantly have(its about the 8th iteration of it) looks like this:
\\\\\\w+\\: Which, as far as I can tell, means this:
the first two \\ are for a literal followed by the next two for a
literal \(this should find a backslash). Then look for all at least 1
character but it doesn't matter how many there are with \w+, then look
for a literal : using \:. Hope that makes more sense.
I don't understand why when I do this its not returning stringn, but it
returns stringn-1 and the letter after the colon. Thanks
Can you use Java's regex classes instead of split()?
Looking for '\\([a-zA-Z]+):' and taking the first group's content seems
to work:
public class regextest2 {
public static void main(String [] asArgs) {
java.util.regex.Pattern p =
java.util.regex.Pattern.compile(asArgs[0]) ;
for(int nArg=1; nArg<asArgs.length; ++nArg) {
System.out.println("looking in '" + asArgs[nArg] + "'") ;
java.util.regex.Matcher m = p.matcher(asArgs[nArg]) ;
if(!m.find()) {
System.out.println(" not found") ;
}
else {
System.out.println(" found: '" + m.group(1) + "'") ;
}
}
}
}
jc@sarah:~/tmp$ /usr/java/jdk1.5.0_01/bin/javac regextest2.java
jc@sarah:~/tmp$ /usr/java/jdk1.5.0_01/bin/java regextest2
'\\([a-zA-Z]+):' "path:\string1\string2\...\stringn:<a letter><may
contain a :>"
looking in 'path:\string1\string2\...\stringn:<a letter><may contain a
:>'
found: 'stringn'