Closed (won't fix)
Project:
Feeds Tamper
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
3 Nov 2011 at 16:14 UTC
Updated:
30 Oct 2013 at 04:18 UTC
Jump to comment: Most recent file
Comments
Comment #1
grasmash commentedAttaching file.
Comment #2
grasmash commentedThis plugin may be growing a bit too niche, but I still think it could be helpful to many people. I've added a few more options. Namely:
- Added ability to set cascading regexs. I.E., if extraction fails, an alternate regex will be used to attempt extraction.
- Added setting to choose fallback behavior if all regexs fail.
This plugin is really useful if you need to comb through a specific XML node that isn't always consistently formatted.
Comment #3
martysteer commentedI think this is a great addition! using backreferences in REGEX is very handy when parsing non-standard XML schema.
For example, I am consuming publisher journal feeds. Some publishers' xml feeds itemise individual journal/issue/page-numbers/doi in their XML feeds and are easy to grab with feeds_xpath_parser. However some put the item values into item descriptions, or concatenate them in various ways.
I am using this module now to extract individual values from xml feed value cases like:
a) American Nineteenth Century History, Volume 12, Issue 3, Page 377, September 2011
b) American Nineteenth Century History, Volume 12, Issue 3, Page 370-371, September 2011
c) American Nineteenth Century History, Volume 12, Issue 3, Page ebi, September 2011
with feed tamper plugin extract via regex:
/.+Volume ([0-9]+), Issue ([0-9]+), Page ([a-z0-9]+)-([a-z0-9]+),.+/
cascade to:
/.+Volume ([0-9]+), Issue ([0-9]+), Page ([a-z0-9]+),.+/
and fallback behaviour:
- leave field value as is.
This catches both single page entries (a)(c) and page ranges (b). I can use $1, $2, $3 or $4.
For the publisher feeds which have the values in specific XML elements, xpath parser pulls these out already, and since the tamper pattern doesn't match, the fallback behaviour is used.
Thankyou for this plugin! Without it I would have had to duplicate my feed importer to accommodate a given publishers XML quirks.
ps. One bug in #2 - add the default value to the fallback form element:
'#default_value' => isset($settings['fallback']) ? $settings['fallback'] : '',
Comment #4
dooug commentedI rolled the above tarball into a patch. I also included the fix that is mentioned in comment #3:
Comment #5
twistor commentedI read the patch, but I see a whole lot of options there that aren't explained. To be honest, I'm not entirely sure how this differs from normal capture group usage.
It looks very interesting, but I really need it laid out further.
Can I start requiring tests? We have a pretty simple unit test class, and lots of examples.
Comment #6
Alcaparra commentedI want to extract the mp3 link of a text and put into an audio field, that I created previously. But I don't understand what I have to put in the field "Subpattern to extract".
http://img706.imageshack.us/img706/6052/62129636.png
I use #4
Comment #7
martysteer commentedI think you need to enclose your regex in slashes:
/pattern/Note sure if your patten is valid. Try the slashes first maybe?
Comment #8
technikh commentedI want to extract the first image in HTML code. I used below regex with "Subpattern to extract" $2
/<\s*?img\s+[^>]*?\s*src\s*=\s*(["'])((\\?+.)*?)\1[^>]*?>/The import returned error.
http://rubular.com/ shows the regex is right.
regex taken from http://stackoverflow.com/questions/1196570/using-regular-expressions-to-...
Comment #9
rerooting commentedThis works great for me. Only bug I'm seeing is this:
Notice: Undefined index: 1 in feeds_tamper_extract_regex_subpattern_helper() (line 135 of /var/www/mow/htdocs/sites/all/modules/contrib/feeds_tamper/plugins/extract_regex.inc).Comment #10
twistor commentedAFAICT, this can be accomplished with regex find/replace.
Comment #11
Alcaparra commented"AFAICT, this can be accomplished with regex find/replace."
How?
Comment #12
twistor commentedYou use regex capture groups () and can arrange them in with $1, $2, etc.