Re: regular expressions help please
| From: | CC Zona | Date: | Tue, 30 Apr 2002 08:30:25 +0000 |
| Subject: | Re: regular expressions help please | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-95336@lists.php.net to get a copy of this message | ||
In article <5.0.2.1.0.20020430004147.032752a8@mail.atfantasy.com>,
osmosis@atfantasy.com (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?
>
> Pull everything except a specific word from a sentence.
<snip more examples>
First you need to decide what you mean by "word". If it's simply "the
stuff separated by a space", then you might find it simpler to explode your
sentences on the space character, then loop through the resulting array
using string functions to do your comparisons . Regex is great for the
power and flexibility it offers, but if you're really struggling with the
syntax, using constructs that are more familiar may help you move forward.
On the other hand, it's frequently the case that one needs a more
sophisticated definition of "word". Is it just adjacent letters? What if
they're interrupted by a hyphen? Are leading/trailing punctuation marks
included? Do adjacent digits count as words? Etc. Once you've defined
the pattern comprising a "word", you can then translate it into regex--or
get more help from others in making the translation.
--
CC