You are here: Re: [PHP] Re: Silly regex giveing me a hard time « PHP « IT news, forums, messages
Re: [PHP] Re: Silly regex giveing me a hard time

Posted by Dotan Cohen on 09/25/94 11:29

On 10/16/05, Darvin <phpit@andrioli.com> wrote:
> Dotan Cohen wrote:
> > I have a list like this:
> > 235 Some info
> > 12323 other 5 things
> > No number on this line!
> > 43 something or other
> >
> > I need to remove the first number from each line, so that I will get this:
> > Some info
> > other 5 things
> > No number on this line!
> > something or other
> >
> > So I tried:
> > $data=preg_replace("//n[ ]*[0-9][ ]*/", "", $data);
> >
> > That is (I think): any amount of spaces, followed by any number,
> > followed by any amount of spaces. This doesn't seem to be the way to
> > do it. Anybody have a better idea? Thanks.
> >
> > Dotan
> > http://technology-sleuth.com
>
> Try
> preg_replace("/^[ ]*[0-9]+[ ]*/", "", $data);
>
> It means: from the beginning of $data looks for space (if any), then
> almost one number followed by space (if any).
>
> If you don't use ^ you may remove the number 5 'from other 5 things'
>
> Darvin
>

Thanks all for the help on this one! Darvin's pointing out about the ^
was great- I couldn't quite figure that one out. You guys are the
greatest.

Dotan
http://technology-sleuth.com/internet/index.php

 

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

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