I am writing a plugin for a Python based open source blog platform (similar to WordPress) on App Engine (with WebApp Framework and Django template)
This plugin is exactly the same as this one: http://wordpress.org/extend/plugins/blog-mechanics-keyword-link-plugin-v01/
A plugin that allows you to define keyword/link pairs. The keywords
are automatically linked in each of your posts.
Here is the key regular expression source code:
// The regular expression comes from an older
// auto link plugin by Sean Hickey. It fixed the autolinking inside a link
// problem. Thanks to [Steph] for the code.
// For keywords with quotes (') to work, we need to disable word boundary matching
if ($ignorecase) $case = "i"; else $case="";
$cleankeyword = preg_quote($cleankeyword,'\'');
if (BM_KEYWORDLINK_QUOTES && strpos( $cleankeyword , '\'')>0)
$regEx = '\'(?!((<.*?)|(<a.*?)))(' . $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
else
$regEx = '\'(?!((<.*?)|(<a.*?)))(\b'. $cleankeyword . '\b)(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
How can I rewrite the regular expressions in Python? I have no experience in PHP.
Thanks a lot!
What have you tried? Go through the
remanual. It has lots of good information in it, and it will answer many of the questions that you could have. For example,re.escapefor making external strings safe.