1. ## URL regex

Hello, I'm trying to pull off the url's within the sorce of my $string below using preg_match_all. I'm currently using: PHP Code: $string = '<p>Id like to add this stuff here:&nbsp;<img src="http://latex.codecogs.com/gif.latex?x^2&amp;plus;3x-4" alt="x^2+3x-4" />&nbsp;is one such formula and&nbsp;&sbquo;another formula is&nbsp;<img src="http://latex.codecogs.com/gif.latex?\frac{a}{b}" alt="\frac{a}{b}" />&nbsp;this one.&nbsp;</p>';  preg_match_all('/"http:\/\/(latex.codecogs.com)\/(gif|svg|png)\.latex\?((.^\")*)"/', $string,$https, PREG_SET_ORDER);  
Basically, each url will start with http://latex.codecogs.com/gif.latex?, but then all bets are off. I think that my regex is correct up through ((.^\")*) which is my attempt at saying "Hey, look for any pattern here except for a quote and then find the final quote. Unfortunately, nothing is found. Any thoughts?

Thank you,

Eric

2. Try this

PHP Code:
 $string = '<p>Id like to add this stuff here:&nbsp;<img src="http://latex.codecogs.com/gif.latex?x^2&amp;plus;3x-4" alt="x^2+3x-4" />&nbsp;is one such formula and&nbsp;&sbquo;another formula is&nbsp;<img src="http://latex.codecogs.com/gif.latex?\frac{a}{b}" alt="\frac{a}{b}" />&nbsp;this one.&nbsp;</p>';$pattern = '#src="(http:\/\/latex.codecogs.com[^"]+)"#s'; if (preg_match_all($pattern,$string, $m)) {$matches = \$m[1]; }  

3. Thanks so much for the response! The pattern works perfectly and almost makes perfect sense. If you wouldn't mind explaining the # at the beginning and the #s at the end, I'd greatly appreciate it...you know, the whole "Give a man a fish vs. Teach a man to fish"

-Eric

4. It's the pattern delimiter (I prefer # instead of /)

5. If your delimiter is #, why are you escaping the /'s ?

6. gvre: Thank you for the response!
StarLion: If one uses # instead of / then we dont' have to do the escaping?

7. most of the examples you see in the manual use / as a delimiter - which is why they have to escape it as \/. Using a different delimiter removes this requirement. (However, if, for example, you wanted to use a literal # in the pattern above, you WOULD have to escape it as \#.

Take a look at the second section of this page of the manual: http://us3.php.net/manual/en/regexp....delimiters.php

8. Perfect! Thanks so much....

9. Originally Posted by StarLion
If your delimiter is #, why are you escaping the /'s ?
by mistake

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•