On Tuesday 30 April 2002 15:51, Ed Lazor wrote:
> I've been banging my head against regular expressions all night... help
> would be greatly appreciated.  Could you give me examples on how to do the
> following?

Is this for a programming assignment/exercise? Do you /have/ to use regex? 
Other methods may be easier. I'll do the two simple ones:

> Pull everything except a specific word from a sentence.  For example,
> pulling everything except the word run from "the water run was steep".

a) Use str_replace(), search for 'run ' (or ' run') and replace with ''.
b) explode() the string, put 'run' (and any other words you don't want) into 
an array, then use array_diff()

> Pull all words from a string starting with a specific letter or
> pattern.  For example, pulling all of the words starting with the letter r
> from "run beep burp ran rin ron runt zoot zip pow"

a) explode() the string, loop through array check 1st char of each element.

> I apologize in advance if these are really simple.  It's just that I'm new
> to regular expressions and reading all of the web page tutorials, manual
> pages, and mailing list archive messages has left me thinking I'm
> complicating something somewhere, because it really shouldn't be this hard.

As you can see, a bit of lateral thinking can get you the same results 
without the headbanging. Using regex can be expensive in terms of CPU cycles 
and very often simpler methods will suffice. By all means learn regexes as 
they are damn useful. But start simple then build upon it.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
A full belly makes a dull brain.
                -- Ben Franklin

                [and the local candy machine man.  Ed]
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to