How to write a regular expression for "everything between X and Y" for use with preg_replace
Posted
by pg
on Stack Overflow
See other posts from Stack Overflow
or by pg
Published on 2010-06-03T17:05:11Z
Indexed on
2010/06/03
17:14 UTC
Read the original article
Hit count: 171
I want to take a variable called $encoded_str and and remove cd1, CD1 and anything between the first 'l' and the last blank space. So for example "lp6 id4 STRINGcd1" would return "STRING".
I'm using PHP 4 for now so I can't use str_ireplace, I have this:
$encoded_str=str_replace('CD1','',$encoded_str);
$encoded_str=str_replace('cd1','',$encoded_str);
$encoded_str=preg_replace('X','',$encoded_str);
I've RTFM for preg_replace but am a bit confused. What should I replace the X with and can you suggest a decent introductory primer for writing regular expressions?
© Stack Overflow or respective owner