[pmwiki-devel] regex question

Dominique Faure dominique.faure at gmail.com
Thu Jan 24 08:16:43 CST 2008


On Jan 24, 2008 1:03 PM, Hans <design5 at softflow.co.uk> wrote:
> For query $pat highlighting I use the following preg_replace on text
> lines $row:
>
> $row = preg_replace("/(\\[@[^\\]]+)($pat)(.*?@\\])/".$qi."", "$1@]$2[@$3", $row);
>
> $row = preg_replace("/($pat)/".$qi."","'''$1'''", $row);
>
> The second surrounds the query match with ''' to create a  bold
> highlight markup.
>
> The first looks for any [@ .... querymatch .... @] and converts it into
>
>  [@ .... @]querymatch[@ .... @]
>
> in order for the '''bold highlight''' to work.
>
> This is fine except in situations where there are several matches
> inside the [@ .... @] brackets:
> [@ ... match ... match ... @]
>
> What regex do I need to cover these cases as well?
>
> Thanks for any ideas!
>
> Hans
>

Perhaps you should proceed using several steps:

1. get the substring enclosed into [@ ... @] markup
2. into this substring, replace all occurences of "matched" by "@]matched[@".
3. rebuild the resulting string.

Hope this help,
Dominique



More information about the pmwiki-devel mailing list