Is it possible with Feeds Tamper to find something in a string and replace all the string with something ?

Ex : I've got a .csv file and column 23 can contain something like:

I need to find if this column contains SSR, and rewrite everyting to 1 or 0

Ex : "XL SSR FR RB"  => "1"
     "XL TL RB"      => "0"

Is this something the tamper module can do ?

If it's possible to convert it to boolean it's even better.


  • There's a reg ex plugin in Feeds Tamper. Can you write a reg ex to count occurrences of SSR? Commented Sep 17, 2015 at 13:11
  • I don't know anything about reg ex, but I will try to take a look
    – Mistraë
    Commented Sep 17, 2015 at 14:07

2 Answers 2


So you'll need two tampers for that field. From the manual:

  1. Find replace REGEX Find and replace a user-specified string using REGEX with an option to limit the number of replacements. See the PHP Manual on PCRE Pattern Syntax for a complete reference, or RegexPal for a quick tester.
  2. Convert to boolean Convert a user-specified string to boolean, with the option of specifying what to do in the case of no match.

Here is a regular expression that will find SSR and replace the entire string with it.



Then match SSR in the Convert to boolean tamper. (Note: The regex in the screen shot is now out of date. Use /\b/(SSR)\b/ instead)

Configure Find replace REGEX Configure Convert to boolean Final result

  • Hey ! Thank you for your answer and for the regex ! Since I didn't tell you everything, I have another request, is it possible with this regex code to do the same with multiple characters ( Ex. find SSR => rewrite everything / find RF => rewrite everything / find RAF => rewrite... so on... ) ? EDIT : oh and this regex doesn't match if SSR if on the begening.
    – Mistraë
    Commented Sep 18, 2015 at 12:19
  • I think you can add the same source field again and map it to another Content type field with its own rewrite. Would that work? Are the destination fields for SSR and RF, RAF &c. different? Matching the SSR at the beginning (or end) of the string would require removing the .+ at the start (and end) of the REGEX which would then match SSSR and SSRR. I will look to see if there is a better way to find the edges of the match. Commented Sep 21, 2015 at 0:58
  • Ok I've updated the regex and the link to use \b (word boundary) instead. See stackoverflow.com/questions/6713310/… Commented Sep 21, 2015 at 1:03

enter image description hereStep 1. Install the Feed Tamper php module and enabled it. https://www.drupal.org/project/feeds_tamper_php

Step 2. Now select the Excute php code option from add plugin regarding the required.

Step 3. Paste the following code there...

    //$field contains the value whatever value you are passing by required column

    $required_column_value = $field;
    $find_str = "SSR";

    $pos = strpos($required_column_value, $find_str);
       return 1;// now $field value would be 1
       return 0;// now $field value would be 0

NOTE :: Here don't confuse due to field name username in screen shot it would be your required field name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.