You are here: Re: regular expression problem « PHP Programming Language « IT news, forums, messages
Re: regular expression problem

Posted by John Dunlop on 11/03/05 21:32

Paul wrote:

> Does anyone know if it's possible to use regular expressions to grab
> all content between two words. For example....
>
> ------
> This is some example text to illustrate my problem and here's another
> my for you.
> ------
>
> I want to grab all text between the words 'some' and 'my' with the
> correct result being ' example text to illustrate '

depends what you mean by 'word', a term which has various meanings.

1 approach to match what's between what's sometimes called orthographic
words could be:

`\bsome\b(.*?)\bmy\b`

the same as Sandman's but with assertions that the sequences <some> and
<my> are in fact orthographic words, that is, at both ends of each are
"word" boundaries (as defined by PHP). without these assertions the
sequence <my> appearing before the word <my> would throw the match.

> The following doesn't work with either ereg or preg_match...
>
> some([^(my)]+)my

because it's a match for <some>, then one or more of any character except
'(', 'm', 'y', or ')' until the last occurrence of <my>.

character classes are not ordered, they're lists of individual characters.

--
Jock

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация