You are here: Re: [PHP] Really simple regex « PHP « IT news, forums, messages
Re: [PHP] Really simple regex

Posted by Dotan Cohen on 06/08/05 18:23

On 6/8/05, Jochem Maas <jochem@iamjochem.com> wrote:
> Dotan Cohen wrote:
> > On 6/8/05, list_fernando@dtcom.com.br <list_fernando@dtcom.com.br> wrote:
> >
> >>Quoting Dotan Cohen <dotancohen@gmail.com>:
> >>
> >>$string="I have xxxxxxxx apples!";
> >>$string=preg_replace("/x+/sim","x", $string);
> >>print "$string";
> >>
> >>hope it helps..
> >>
> >>
> >>>Now, I know that this is easy, but I am embarassed to say that I can't
> >>>find a regex tutorial that will show me how to match any occurances of
> >>>x and replace them with one x:
> >>>
> >>>xxxxx >x
> >>>xx > x
> >>>x > x
> >>>
> >>>$string="I have xxxxxxxx apples!";
> >>>$string=preg_replace("-regex here-","x", $string);
> >>>print "$string";
> >>>
> >>>I have x apples!
> >>>
> >>>I searched marc because I know that I've seen this, but I don't know
> >>>on what keywords to search. I know that php uses perl-compatable
> >>>regular expressions, but in no tutorial did I find this. I know that *
> >>>matches any amount of occurances of a string, but formulating it to do
> >>>it in the middle of a string of text I could not get.
> >>>
> >>>Dotan
> >>>http://lyricslist.com/lyrics/artist_albums/19/adams_bryan.php
> >>>Bryan Adams Lyrics
> >>>
> >>>--
> >>>PHP General Mailing List (http://www.php.net/)
> >>>To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>
> >
> > Thanks, that did it. I did not know about the +. And what is the 'sim'
>
> its not one thing but 3 things, everything that comes after a
> regexp closing marker (but inside the string) is treated as a regexp modifier,
> in this case the modifiers are:
>
> modifer - meaning
> ------------------------------------
> s - PCRE_DOTALL
> i - PCRE_CASELESS
> m - PCRE_MULTILINE
>
> read more here: http://nl3.php.net/manual/en/reference.pcre.pattern.modifiers.php
>
> > doing? I can't find any information on that.
> >
> > Dotan
> > http://lyricslist.com/lyrics/artist_albums/64/beatles.php
> > Beatles Lyrics
> >
>

Thank you for that link! I have so much to learn (there is so much to learn).

Dotan
http://lyricslist.com/forum/index.php
Lyrics Forum

 

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

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