|
Posted by Curtis on 01/22/07 12:11
On Jan 20, 6:18 pm, "Rik" <luiheidsgoe...@hotmail.com> wrote:
> windandwaves wrote:
> > How can I write the thing below as a regular expression
> > (preg_replace)?
>
> > $array = array("-0", "-1", "-2", "-3", "-4");
> > $key = str_replace($array, "", $key);
>
> I would normally not use a regular expression for this (str_replace is
> often faster), but here you go:
>
Yes, that's a good point. In some situations it may be better to use
str_replace, substring, or similar functions.
> preg_replace('/-[0-4]/','',$key);
>
> http://regularexpressions.info
>
> --
> Rik Wasmus
For me, the best way to learn was just trying to apply regex in
projects I was already doing. At first, I spent a lot of time
debugging, until I eventually started getting the hang of them (now one
of my favorite features in a language). Tutorials that demonstrated
with strings like "aaabc" often made it harder for me to grasp.
However, http://regularexpressions.info is a pretty good reference
Curtis
Navigation:
[Reply to this message]
|