regular expression

C

Christine Mayer

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
 
G

Gordon Beaton

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

--
 
P

Piotr Kobzda

Christine said:
I need a regular expression - it should:

Allow all Strings that do not begin with "car_"

Why reqex for that?

!s.startsWith("car_")


piotr
 
I

Ingo Menger

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"
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top