pipe2py icon indicating copy to clipboard operation
pipe2py copied to clipboard

Regex module can't handle more than one sub_field substition

Open thwarted opened this issue 11 years ago • 1 comments

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


thwarted avatar Jul 25 '13 07:07 thwarted

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

reubano avatar Nov 09 '14 11:11 reubano