You are here: Preg_match not always returning first match? « All PHP « IT news, forums, messages
Preg_match not always returning first match?

Posted by FFMG on 08/23/06 06:28

Hi,

If I have a string:
$s = "sometext more_text hello1hello2";

And I want to look for the text 'hello', I do the following regex
search
/hello([0-9]*)/is
And I get the expected value of '1', (the first hello)

But if I do
/.*hello([0-9]*)/is
I get the next 'hello', ('2').

But, because I want find the first 'hello' _after_ 'sometext', I want,
(need?), to do

/sometext.*hello([0-9]*)/is

But that returns the second 'hello' not the first one.

What could I be doing wrong?

Thanks

FFMG

 

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

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