Re: Regex help
| From: | Michal Migurski | Date: | Mon, 15 Mar 2004 17:26:43 +0000 |
| Subject: | Re: Regex help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-180479@lists.php.net to get a copy of this message | ||
>I will have a variable: $the_extention which will have a value like:
>98797-234234--2c-something-2c
>
>How do I take out the part which will always start with "--2c" and will
>always end with "-2c"
You could use preg_replaces, like so:
$result = preg_replace('/--2c.+-c/', '', $the_extention);
That matches anything between '--2c' and '-2c' and replaces it with
''.
You could also use preg_match, like so:
preg_match('/^(.+)--2c.+-c$/', $the_extention, $matches);
$matches[1] should contain the substring you need.
>A good "baby steps" tutorial on regex too would be appreciated.
Chapter 7 of Learning Perl is an excellent tutorial and basic reference.
http://www.oreilly.com/catalog/lperl3/
As usual, the trusty PHP manual also has good information:
http://www.php.net/manual/en/pcre.pattern.syntax.php
---------------------------------------------------------------------
michal migurski- contact info and pgp key:
sf/ca http://mike.teczno.com/contact.html