regular expression

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi Gurus,

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 am trying to learn regular expressions, but I find them hard and this
seems like a really simple place to start....



Re: regular expression

windandwaves wrote:
Quoted text here. Click to load it

I would normally not use a regular expression for this (str_replace is
often faster), but here you go:


Quoted text here. Click to load it

Rik Wasmus

Re: regular expression

Quoted text here. Click to load it

Yes, that's a good point. In some situations it may be better to use
str_replace, substring, or similar functions.

Quoted text here. Click to load it

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, is a pretty good reference


Site Timeline