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