regular expression

Discussion in 'Java' started by Christine Mayer, Oct 15, 2007.

  1. 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
     
    Christine Mayer, Oct 15, 2007
    #1
    1. Advertising

  2. 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

    --
     
    Gordon Beaton, Oct 15, 2007
    #2
    1. Advertising

  3. Christine Mayer

    Christian Guest

    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..
     
    Christian, Oct 15, 2007
    #3
  4. 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

    --
     
    Gordon Beaton, Oct 15, 2007
    #4
  5. Christine Mayer

    Piotr Kobzda Guest

    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
     
    Piotr Kobzda, Oct 15, 2007
    #5
  6. Christine Mayer

    Ingo Menger Guest

    On 15 Okt., 12:34, Christine Mayer <> 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"
     
    Ingo Menger, Oct 15, 2007
    #6
  7. Christine Mayer, Oct 15, 2007
    #7
  8. Christine Mayer

    Piotr Kobzda Guest

    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
     
    Piotr Kobzda, Oct 15, 2007
    #8
  9. Christine Mayer

    Tim Smith Guest

    In article <>,
    Christine Mayer <> 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
     
    Tim Smith, Oct 16, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Keith-Earl
    Replies:
    1
    Views:
    474
    Mary Chipman
    Jun 15, 2004
  2. VSK
    Replies:
    2
    Views:
    2,379
  3. =?iso-8859-1?B?bW9vcJk=?=

    Matching abitrary expression in a regular expression

    =?iso-8859-1?B?bW9vcJk=?=, Dec 1, 2005, in forum: Java
    Replies:
    8
    Views:
    881
    Alan Moore
    Dec 2, 2005
  4. GIMME
    Replies:
    3
    Views:
    12,046
    vforvikash
    Dec 29, 2008
  5. Noman Shapiro
    Replies:
    0
    Views:
    254
    Noman Shapiro
    Jul 17, 2013
Loading...

Share This Page