Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / July 2006

Tip: Looking for answers? Try searching our database.

Reg ex and not match

Thread view: 
sks - 09 Jul 2006 10:12 GMT
I'm a bit stuck on how to not match something in a reg ex,

Ie, if I wanted to test that a string did not begin with ABC

Do I have to use a character class and do something like this
[^(ABC)]

???
hiwa - 09 Jul 2006 10:33 GMT
sks :

> I'm a bit stuck on how to not match something in a reg ex,
>
[quoted text clipped - 4 lines]
>
> ???
Basically and generally, regular expression can't do it.
But your Java program that utilizes regex could do.
Jeffrey Schwab - 09 Jul 2006 16:41 GMT
> I'm a bit stuck on how to not match something in a reg ex,
>
> Ie, if I wanted to test that a string did not begin with ABC
>
> Do I have to use a character class and do something like this
> [^(ABC)]

No.  The character-class will match one character that is none of A, B,
C, or either parenthesis.  Try this:

    Pattern.compile("^(?!ABC)");
Oliver Wong - 10 Jul 2006 15:48 GMT
> I'm a bit stuck on how to not match something in a reg ex,
>
[quoted text clipped - 4 lines]
>
> ???

   Your regular expression would basically say this (in plain English):

( String does NOT start with A. )
OR
( String starts with A, but does NOT have a B following it)
OR
( String starts with AB, but does not have a C following it)

   I'm not familiar with Java's specific syntax for regular expressions,
but it'd probably look something like:

([^A])|(A[^B])|(AB[^C])

possibly with the addition of "string start" and "string end" markers.

   - Oliver


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.