Re: [RegExp] extracting anchors
| From: | Jens Lehmann | Date: | Thu, 13 Mar 2003 16:30:17 +0000 |
| Subject: | Re: [RegExp] extracting anchors | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-139537@lists.php.net to get a copy of this message | ||
Jome wrote:
Jens Lehmann wrote:This is of course a working solution, but I'm still interested if it can be done directly with just one regular expression. Thanks anyways. JensHello, I want to extract the "name"-attribute of all anchors out of an HTML-source-code which don't have the "href"-attribute. I can use this code to get the "name"-attribute: preg_match_all('/<a([^>]*?)name=[ \'\"](.*?)[ \'\"](.*?)>/is',$src,$ar); The name-attributes are now in $ar[2]. How can I exclude all links which have the href-attribute? I didn't find an easy way how to say that a string must _not_ be part of a pattern match. I hope you can give me some advise.This is one lousy solution but hey - it's a solution after all; you can simply remove all <a> tags containing href before doing the preg_match_all()-call, something like this below should do it I think. $src = preg_replace('/<a[^>]*?href=[^>]*?>/is', '', $src);