ggaughan / pipe2py

A project to compile Yahoo! Pipes into Python (see it hosted on Google App Engine: http://pipes-engine.appspot.com)
http://wiki.github.com/ggaughan/pipe2py
GNU General Public License v2.0
317 stars 51 forks source link

Regex module can't handle more than one sub_field substition #23

Open thwarted opened 11 years ago

thwarted commented 11 years ago

I have a Regex module call that replaces with a string that has multiple sub-fields in it:

${img.title} and ${pubDate}

The regular expression that matches the field names here is too greedy and eats up too much of rest of the string. Making the regular expression non-greedy ( (.+?) rather than (.+) ) fixes this.

diff --git a/modules/piperegex.py b/modules/piperegex.py
index 082e9aa..80a8637 100644
--- a/modules/piperegex.py
+++ b/modules/piperegex.py
@@ -61,7 +61,7 @@ def pipe_regex(context, _INPUT, conf, **kwargs):
             if rule[0] in item and item[rule[0]]:
                 util.set_value(item, rule[0], re.sub(rule[1], rule[2], unicode(item[rule[0]])))

-                util.set_value(item, rule[0], re.sub('\$\{(.+)\}', sub_fields, unicode(item[rule[0]])))
+                util.set_value(item, rule[0], re.sub('\$\{(.+?)\}', sub_fields, unicode(item[rule[0]])))

         yield item
reubano commented 9 years ago

I just made a bunch of updates, can you check and see if the issue is still there?