Re: Getting part of string matched with regular expressions
| From: | Jim Lucas | Date: | Mon, 28 Jan 2008 16:19:35 +0000 |
| Subject: | Re: Getting part of string matched with regular expressions | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-268198@lists.php.net to get a copy of this message | ||
Teck wrote:
Hi, I'm trying to find a way to get part of a string where the part is matched with regular expressions. So, for example, if I have a string: a2b3cd5ef6ghi7232jklmn I need to grab "12b3cd5" using regular expressions and store the part in a variable.how do you decide what the above quoted string is going to be? 1. Will is always be in the same position in the string? 2. Will the pattern always be the same? (##x#xx#) ? 3. Will you be supplying the patter or search string from an outside source?
$var = do_something("","","a2b3cd5ef6ghi7232jklmn"); I was using preg_replace for this, and try to delete (i.e., replace the non-matched part with an empty string) the second part, but I can't make it work.-- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare