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 / October 2007

Tip: Looking for answers? Try searching our database.

regular expression

Thread view: 
Christine Mayer - 15 Oct 2007 11:34 GMT
Hi,

I need a regular expression - it should:

Allow all Strings that do not begin with "car_"

Examples - ok would be:
car
carwash
1
a
1234
abcdefgh
a1b2

not ok was:
car_
car_1
car_a
car_1234
car_abcdefgh
car_a1b2

On Google, I basically found the expression:
.*(?<!car_)wash

On its basis, I build:
(?<!car_)[0-9A-Za-z_+\-]+

However, it doesn't work as required - I guess, because the String
that follows
defined by  "0-9A-Za-z_+\-" could be "car_" too! In other words, this
rule says
Don't start the String with "car_" but after that you may write car_ -
so the String MAY begin with car_

Any idea how to fix that?

Thx,

Christine
Gordon Beaton - 15 Oct 2007 12:17 GMT
> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"

e.g.

"^(?!car_)[a-zA-Z0-9_+-]*"

/gordon

--
Christian - 15 Oct 2007 12:21 GMT
Gordon Beaton schrieb:
>> I need a regular expression - it should:
>>
[quoted text clipped - 7 lines]
>
> --

though that won't match if the string contains a linefeed..
Gordon Beaton - 15 Oct 2007 12:28 GMT
> though that won't match if the string contains a linefeed..

It won't make coffee either, but the original poster didn't ask for
either of those things.

/gordon

--
Piotr Kobzda - 15 Oct 2007 13:34 GMT
> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"

Why reqex for that?

!s.startsWith("car_")

piotr
Christine Mayer - 15 Oct 2007 14:01 GMT
> Why reqex for that?
>
> !s.startsWith("car_")
>
> piotr

Because I am using http://tuckey.org/urlrewrite/
Piotr Kobzda - 15 Oct 2007 14:37 GMT
>> Why reqex for that?

> Because I am using http://tuckey.org/urlrewrite/

OK, I asked because people sometimes uses regex without a real need for
that.  In your case, it seems there is no other way...  So, refer to the
Gordon's response, or try the following:

"(?!car_)(?s).*"

piotr
Ingo Menger - 15 Oct 2007 13:56 GMT
> Hi,
>
> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"
[stuff deleted]
> Any idea how to fix that?

Sometimes it is possible to reformulate the problem:

"For all strings that do not begin with 'car_' do X"
==>
"For all strings do if it begins with 'car_' then nothing else X"
Tim Smith - 16 Oct 2007 05:25 GMT
> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"

^([^c]|c[^a]|ca[^r]|car[^_])

Signature

--Tim Smith



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



©2008 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.