[pmwiki-users] Category Markup
Patrick R. Michaud
pmichaud at pobox.com
Fri Dec 16 23:47:02 CST 2005
On Sat, Dec 17, 2005 at 12:32:09AM -0500, DaveG wrote:
> I'm having trouble with regular expression replacement.
>
> Start String : "Tags: a,b, c"
> Result String: "Tags: [[!a]],[[!b]], [[!c]]"
>
> $ROSPatterns["/^Tag(s?):\\s([A-Za-z0-9]\s?)+([,]\s?([A-Za-z0-9]\s?)+)*$/i"]
> = "Tags: [[!\$2]]";
Because of the repeated names on a line I don't think this can
be done via a regular expression substitution in PHP. AFAIK, a repeated
regex pattern like (,\s?([A-Za-z0-9]\s?)+)* will capture and replace
only the last matching repetition.
I think it'll have to be done in two steps: a pattern to recognize
the Tags: line, and a second one in a subroutine to convert the tags.
So, perhaps something like:
$ROSPatterns["/^Tags?:\\s*([\\w\\s,]+)/e"] = "TagsToCategories('$1')";
function TagsToCategories($tags) {
return preg_replace('/\\w+/', '[[!$0]]', $tags);
}
Pm
More information about the pmwiki-users
mailing list