You are here:  » Normalize products with Search And Replace (RegExp)


Normalize products with Search And Replace (RegExp)

Submitted by sirmanu on Sat, 2019-01-12 10:04 in

Hi David.

I want to normalise some products name with filters so they keep group together.

For instance, I have these products:

1 - Nike Zoom Zapatillas entrenamiento para hombre
2 - Nike Zoom Zapatillas entrenamiento hombre
3 - Nike Zoom Zapatillas para hombre
4 - Nike Zoom Zapatillas hombre

SO, what I do here, is to use Searcn and Replace (RegExp) filter (posted in other thread).

I use

search: /Entrenamiento para/i
replace: Entrenamiento

and

search: /Zapatillas para/i
replace: Zapatillas

With this procedure, 1 is equals to 2, and 3 to 4.

However, this is going to be complex and I am going to start to have multiple filters. For instance, I would need add the same filter for "ropa" , instead of zapatillas.

Is any way I can use these filters grouped into one?
Search: /(Entrenamiento|Zapatillas) para/i
Replace: Something like $1

Is it possible?

Thanks!

Submitted by support on Mon, 2019-01-14 10:55

Hi,

The back references should work fine with Search and Replace RegExp - I just tested using this version:

  /*************************************************/
  /* searchReplaceRegExp */
  /*************************************************/
  $filter_names["searchReplaceRegExp"] = "Search and Replace (RegExp)";
  function filter_searchReplaceRegExpConfigure($filter_data)
  {
    widget_textBox("Search","search",TRUE,$filter_data["search"],"",3);
    widget_textBox("Replace","replace",FALSE,$filter_data["replace"],"",3);
  }
  function filter_searchReplaceRegExpValidate($filter_data)
  {
    if (!$filter_data["search"])
    {
      widget_errorSet("search","required field");
    }
  }
  function filter_searchReplaceRegExpExec($filter_data,$text)
  {
    return trim(preg_replace($filter_data["search"],$filter_data["replace"],$text));
  }

Using search:
/(Entrenamiento|Zapatillas) para/i

and replace:
$1

Cheers,
David.
--
PriceTapestry.com

Submitted by sirmanu on Tue, 2019-01-15 09:49

It works perfectly, I don't know why it wasn't working before.
This is one of the best filters if you master REGEX!