Brian,
You need to escape back slash in Java: type \\w intstead of "\w"
Best of luck,
Yuriy Zubarev
----- Original Message -----
From: "Brian Elliott" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Saturday, December 15, 2001 6:37 AM
Subject: Simple example needed
> I am very familiar with Perl regular expression and have used
> org.apache.regexp.RE package for a little while but only for simple
> matching. How do I match a word in a regular expression? According to
> the RE javadocs:
>
> \w Matches a "word" character (alphanumeric plus "_")
>
> So could someone give me some example Java code? I am analyzing a file
> path and want to grab the first directory name (ex. "/dir1/dir2/dir3").
> Like:
>
> String path = "/dir1/dir2/dir3";
> RE exp = new RE ("^/([\w])/.*");
> boolean matched = exp.match(path);
> String insideParens = exp .getParen(1);
>
> The compiler complains about \w being invalid. Do I have to put the \w
> inside of colons or something? Or not include the braces?
>
> Also, I know I need to apply the pattern to my path String but do I have
> to use the match method or are there other ways of doing it?
>
> Any help would be appreciated.
>
> Brian
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>