Using regex: php regular expression to match string if NOT in an HTML tag on newest questions tagged regex – Stack Overflow
I’m trying to solve this bug in Drupal’s Hashtags module: http://drupal.org/node/1718154
I’ve got this function that matches every word in my text that is prefixed by “#”, like #tag:
function hashtags_get_tags($text) {
$tags_list = array();
$pattern = "/#[0-9A-Za-z_]+/";
preg_match_all($pattern, $text, $tags_list);
$result = implode(',', $tags_list[0]);
return $result;
}
I need to ignore internal links in pages, such as <a href="#reference">link</a>, or, more in general, any word prefixed by # that appears inside an HTML tag (so preceeded by < and followed by >).
Any idea how can I achieve this?
See Answers
source: http://stackoverflow.com/questions/11856858/php-regular-expression-to-match-string-if-not-in-an-html-tag
Using regex: using-regex
Recent Comments