Page 1 of 1
Markup:Regex
Posted: Mon Mar 15, 2010 12:06 pm
by Ansgar
Hiho!
I want to use the Regex-Plugin zu change the link-syntax in the articles.
A link like this
Code: Select all
<a href="http://board.s9y.org">s9y Forum</a>
should be changed into this
Code: Select all
<a href="http://board.s9y.org" target="_blank">s9y Forum</a>
and this should work for Links with title-tags too.
I´m trying to understand and adapt the ClickableURL example, but as I'm new to regular expression and the Plugin, I don`t get it...
Are the items in the SearchArray alternatives that is searched for?
What do the numbers in the Replace Array represent? \\1 \\2 \\3 \\4
Regards
Ansgar
Re: Markup:Regex
Posted: Mon Mar 15, 2010 12:23 pm
by garvinhicking
Hi!
A rule like
Code: Select all
$regexpArray = array(
'SearchArray'=>array(
'@<a ([^>]+)>@i',
),
'ReplaceArray'=>array(
'<a target="_blank" \\1>'
)
);
should do the trick. When you already use "target=_blank" somewhere, you'd get it a second time. Working around that is pretty tricky with RegExps, but having two attributes would work in every browser still.
Are the items in the SearchArray alternatives that is searched for?
SearchArray can contain as many patterns as you might want to use, so a single PHP-File could take care of multiple replacements.
What do the numbers in the Replace Array represent? \\1 \\2 \\3 \\4
Those are placeholdes for strings that have been matched with (...) in the searchArray, which can then be inserted into the string.
Best regards,
Garvin
Re: Markup:Regex
Posted: Mon Mar 15, 2010 12:49 pm
by Ansgar
Hiho Garvin,
thank a lot!
meanwhile I've found another working solution:
Code: Select all
$regexpArray = array(
'SearchArray'=>array(
// a well formatted link with no extra attributes
"/<a href=\"([^\"]*)\">(.*)<\/a>/iU"
),
'ReplaceArray'=>array(
'<a href="\\1" target="_blank">\\2</a>'
)
);
Which one is better?
SearchArray can contain as many patterns as you might want to use, so a single PHP-File could take care of multiple replacements.
so the first item in SearchArray is replaced by the first item in ReplaceArray?
... and the multiple files in serendipy_event_regexp/regexps or for clearness only?
Best regards,
Ansgar
Re: Markup:Regex
Posted: Mon Mar 15, 2010 1:43 pm
by garvinhicking
Hi!
This one is more problematic, if you have a link <a title="mylink" href="..."> then it will not be rewriten. My version transfers every <a.*>-Tag...
... and the multiple files in serendipy_event_regexp/regexps or for clearness only?
They are seperated so that you can selectively delete some files if you don't want that specific markup.
Regards,
Garvin
Re: Markup:Regex
Posted: Mon Mar 15, 2010 2:15 pm
by Ansgar
Hiho!
Ok, then I'll use your version
Thanks a lot for your help!
Best Regards,
Ansgar