Han top-posted:
"Pedro" <he****@hotpop.com> wrote in message
news:bl************@ID-203069.news.uni-berlin.de... Han wrote: > Yet another newbie regular expression question (I swear, I'm learning!)
>
> I have a simple pattern that captures an anchor tag:
>
> (<a.*?</a>)
>
> It works great. I would now like to modify this to EXCLUDE occasional
> opening and closing bold tags (<b></b>) around the text.
I think your best bet would be to preg_replace() the bold out:
$anchor = preg_replace('#</?b>#i', '', $anchor);
I was exploring ways to do it in one pass, but I could easily do as you
suggest before outputting each anchor to the page.
ok ... try this if you really want one single pass
<?php
$regex = '#(<a.*)>(?:<b>)?([^<]*)(?:</b>)?</a>#Ui';
### \_____/\______/\_____/\_______/ |`- case insensitive
### | | | | `- ungreedy
### | | | `- optional "</b>" not captured
### | | `- linked text; if .* matches <b>
### | | so anything but "<" instead :)
### | `- optional "<b>" not captured
### `- the "<a ...>" tag and its parameters
preg_match($regex, $text, $results);
echo $results[1], $results[2], '</a>';
?>
--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.