Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Regex question

Status
Not open for further replies.

AcidHawk

Technical User
Mar 14, 2001
17
0
0
ZA
Hi,

I am having difficulty groking this regex stuff. I have a string:
"SomeStuff D: Drive is full"

In perl I can do something like if (my $var =~ /\s{1}.:\s/) { ...} where I can check the string to see if there is any occurance of space-anyletter-colon-space

I am trying to do the same in java.. I have...

Pattern p1 = Pattern.compile("\\s\\w:\\s");
Matcher m1 = p1.matcher(myString);
if (m1.matches()) {
System.out.println("MATCH FOUND:" + m1.group(1));
System.out.println("MATCH FOUND:" + m1.group(2));
}
else {
System.out.println("NO MATCH FOUND");
}

This does NOT work.. Can any-one tell me where I am going wrong?

In group(1) I am looking for "SomeStuff" and in group(2) I am looking for "D: Drive is full"

Many thanks
AcidHawk

----
Of All the things I've lost in my life it's my mind I miss the most.
 
AcidHawk :

please do not crosspost (Java Sun forum).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top