-2

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!

Susan Mayer
  • 335
  • 1
  • 3
  • 12
  • 3
    What part of re-writing the regular expressions are you having trouble with? What have you tried? – David Wolever Jun 09 '12 at 15:59
  • @SusanMayer: You are basically asking us to do it for you, which is not welcome on StackOverflow. You need to put some effort into it first, or you will not get any (or very little) help. Maybe you should read about [PCRE (Perl-Compatible Regular Expressions) in PHP](http://www.php.net/manual/en/book.pcre.php) first, or try to implement the same feature not by rewriting the PHP code letter-by-letter. PHP has multiple disadvantages in comparison to Python, so basing on the feature definition and not on the actual implementation may be a better idea. – Tadeck Jun 09 '12 at 17:25

1 Answers1

1

What have you tried? Go through the re manual. It has lots of good information in it, and it will answer many of the questions that you could have. For example, re.escape for making external strings safe.

Has QUIT--Anony-Mousse
  • 76,138
  • 12
  • 138
  • 194