468,249 Members | 1,448 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

Regular expression ?

Hello.

I'm stuck! :)

I need a regular expr. that would match any expresion that doesn't start
with some words (not letters - words!)

For example - reg. expr. that matches any expression that doesn't start with
words 'one' and 'two' ??

thanks !!


Jul 17 '05 #1
5 1515
"Josip Maslać" wrote:

I need a regular expr. that would match any expresion that doesn't start
with some words (not letters - words!)

For example - reg. expr. that matches any expression that doesn't start with
words 'one' and 'two' ??


if (!preg_match("/^(one|two)/", $foo)) {
//do stuff
}

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #2
Shawn Wilson wrote:
if (!preg_match("/^(one|two)/", $foo)) {
//do stuff
}


I would do it like this, then you can put the words in an array.
(extending Shawn's version a little bit)

$wordlist = array("one","two","three");
if(preg_match("/^(".join("|",$wordlist).")/i", $foo)
{
// matched
}

greetz
Paul.
Jul 17 '05 #3
"Shawn Wilson" <sh***@glassgiant.com> wrote in message
news:40***************@glassgiant.com...
"Josip Maslać" wrote:

I need a regular expr. that would match any expresion that doesn't start
with some words (not letters - words!)

For example - reg. expr. that matches any expression that doesn't start with words 'one' and 'two' ??


if (!preg_match("/^(one|two)/", $foo)) {
//do stuff
}


Many thanks, but that is not really what I'm looking for.

Like I said, I need just a reg. expression(!) that does what I need - not a
work a round like this (solving it with !preg_match()).
My question was just a part of the problem I need to solve, so this solution
doesn't work for me.
What I need is something like negating the class but on strings:
for example:
'/^[^ot]/' - matches all expressions that doesn't start with o or t,
I need something like that but one whole string, not just letters.
thanks
Jul 17 '05 #4
"Josip Maslac" <jo**********@fer.hr> wrote in
news:c0**********@sunce.iskon.hr:
Like I said, I need just a reg. expression(!) that does what I need -
not a work a round like this (solving it with !preg_match()).
My question was just a part of the problem I need to solve, so this
solution doesn't work for me.
What I need is something like negating the class but on strings:
for example:
'/^[^ot]/' - matches all expressions that doesn't start with o
or t,
I need something like that but one whole string, not just letters.


You could use a negative lookahead:

/^(?!(one|two)\b)/
Jul 17 '05 #5
> You could use a negative lookahead:

/^(?!(one|two)\b)/


That's what I'm looking for !

Thanks !
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Buddy | last post: by
4 posts views Thread by Neri | last post: by
11 posts views Thread by Dimitris Georgakopuolos | last post: by
3 posts views Thread by James D. Marshall | last post: by
7 posts views Thread by Billa | last post: by
9 posts views Thread by Pete Davis | last post: by
25 posts views Thread by Mike | last post: by
1 post views Thread by NvrBst | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kermitthefrogpy | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.