[prev in list] [next in list] [prev in thread] [next in thread]
List: jakarta-regexp-user
Subject: Re: Simple example needed
From: Brian Elliott <elliott8 () ix ! netcom ! com>
Date: 2001-12-20 12:42:34
[Download RAW message or body]
Thanks for both suggestions - I got things to work.
Brian
Ed Chidester wrote:
>
> Brian,
>
> Yuriy's suggestion will get your code to compile... But, your regular
> expression won't match the text you're looking for.
>
> You need to get rid of the square braces otherwise you'll only match a first
> directory with a name of "\" or "w"
>
> I suggest you try
> RE exp = new RE ("^/(\\w+)/.*");
>
> this will match one or more word characters in-between the first two slashes.
>
> Ed.
>
> On Saturday 15 December 2001 02:08 pm, Yuriy Zubarev wrote:
> > Brian,
> >
> > You need to escape back slash in Java: type \\w intstead of "\w"
> >
> > Best of luck,
> > Yuriy Zubarev
> >
> > ----- Original Message -----
> > From: "Brian Elliott" <elliott8@ix.netcom.com>
> > To: <regexp-user@jakarta.apache.org>
> > 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:regexp-user-unsubscribe@jakarta.apache.org>
> >
> > > For additional commands, e-mail:
> >
> > <mailto:regexp-user-help@jakarta.apache.org>
> >
> >
> > _________________________________________________________
> > Do You Yahoo!?
> > Get your free @yahoo.com address at http://mail.yahoo.com
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <mailto:regexp-user-unsubscribe@jakarta.apache.org> For additional
> > commands, e-mail: <mailto:regexp-user-help@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail: <mailto:regexp-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:regexp-user-help@jakarta.apache.org>
--
+-------------------------------+----------------------------------+
| Brian Elliott | Unplugged Systems / ESWC.com / |
| President & CTO | ES Innovation Labs |
| belliott@unpluggedsystems.com | MLS Unplugged & Wireless Systems |
| 719.487.1437 | http://www.unpluggedsystems.com |
+-------------------------------+----------------------------------+
--
To unsubscribe, e-mail: <mailto:regexp-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:regexp-user-help@jakarta.apache.org>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic