Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > regular expression

Reply
Thread Tools

regular expression

 
 
Christine Mayer
Guest
Posts: n/a
 
      10-15-2007
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

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      10-15-2007
On Mon, 15 Oct 2007 03:34:15 -0700, Christine Mayer wrote:
> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"


e.g.

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

/gordon

--

 
Reply With Quote
 
 
 
 
Christian
Guest
Posts: n/a
 
      10-15-2007
Gordon Beaton schrieb:
> On Mon, 15 Oct 2007 03:34:15 -0700, Christine Mayer wrote:
>> I need a regular expression - it should:
>>
>> Allow all Strings that do not begin with "car_"

>
> e.g.
>
> "^(?!car_)[a-zA-Z0-9_+-]*"
>
> /gordon
>
> --
>

though that won't match if the string contains a linefeed..
 
Reply With Quote
 
Gordon Beaton
Guest
Posts: n/a
 
      10-15-2007
On Mon, 15 Oct 2007 13:21:34 +0200, Christian wrote:
> 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

--
 
Reply With Quote
 
Piotr Kobzda
Guest
Posts: n/a
 
      10-15-2007
Christine Mayer wrote:

> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"


Why reqex for that?

!s.startsWith("car_")


piotr
 
Reply With Quote
 
Ingo Menger
Guest
Posts: n/a
 
      10-15-2007
On 15 Okt., 12:34, Christine Mayer <(E-Mail Removed)> wrote:
> 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"


 
Reply With Quote
 
Christine Mayer
Guest
Posts: n/a
 
      10-15-2007
> Why reqex for that?
>
> !s.startsWith("car_")
>
> piotr


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

 
Reply With Quote
 
Piotr Kobzda
Guest
Posts: n/a
 
      10-15-2007
Christine Mayer wrote:

>> 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
 
Reply With Quote
 
Tim Smith
Guest
Posts: n/a
 
      10-16-2007
In article <(E-Mail Removed). com>,
Christine Mayer <(E-Mail Removed)> wrote:
> I need a regular expression - it should:
>
> Allow all Strings that do not begin with "car_"



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



--
--Tim Smith
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Seek xpath expression where an attribute name is a regular expression GIMME XML 3 12-29-2008 03:11 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C++ 42 11-04-2008 12:39 PM
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" Adem C Programming 45 11-04-2008 12:39 PM
Matching abitrary expression in a regular expression =?iso-8859-1?B?bW9vcJk=?= Java 8 12-02-2005 12:51 AM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments