You are here:  » Removing text from end of product name


Removing text from end of product name

Submitted by paddyman on Mon, 2007-12-31 15:52 in

Hi David,

Last question from me this year, I promise :)

One of the feeds I'm using has XBox 360 after each product name.

Call of Duty 4 Modern Warfare XBOX 360
Assassins Creed XBOX 360

Was looking at getting rid of the XBOX 360 part so that the product name matches those from other feeds. Search and replace would work, but there are also some products such as the XBOX 360 console and products which need this text. Can you think of any other way of removing it from the end of products but not from the start?

As you know I'm using the product mapping feature and can always throw these product names in there, but will speed me up if I can remove the text from the end.

Hope theres an easy solution.

Thanks :)

Adrian

Submitted by support on Mon, 2007-12-31 16:05

Hi Adrian,

I've been meaning to write a search and replace by regular expression filter for some time, so this is a good excuse to have a go.... Here it is:

  /*************************************************/
  /* 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));
  }

Add the above code to includes/filter.php. This will add a new filter option, "Search and Replace (RegExp)" which will operate just like Search and Replace, except that the search text is a regular expression which can therefore imply where in the string the text is to be matched (i.e. beginning or end). The regular expression character that will anchor text to the end of the string is $, so in your case you can use this new filter to search for:

XBOX 360$

(and replace with nothing)

Hopefully that should do the trick!

Cheers,
David.

Submitted by paddyman on Mon, 2007-12-31 16:19

Pure Genius,

If there was a nobel prize for PHP you'd be a definite. This saves more time yet again :)

Thanks for everything in 2007. Anyone reading this thread and who is considering purchasing PT, go for it. Its been the best few pounds I ever spent. Scout around the questions on this forum and you'll be amazed by what this software and Davids little tricks can do.

Enjoy new years night.

Cheers

Adrian

Submitted by ChrisNBC on Fri, 2014-12-12 12:03

Hi David,

Hope all is going well.

I would like to use the 'searchReplaceRegExp' filter above to strip sizes off of merchant product names in a feed. The sizes are in the format '30x34'. I wondered if you might be able to suggest what the regular expression would be to identify and remove the sizing information so that all size variations could be recognised/removed.

Thanks in advance.

Regards
Chris

Submitted by support on Fri, 2014-12-12 13:24

Hi Chris,

Have a go with:

\d\dx\d\d

"\d" matches any digit character (0-9) so that should do the trick...
Cheers,
David.
--
PriceTapestry.com

Submitted by ChrisNBC on Mon, 2014-12-15 16:06

Hi David,

Hope you had a good weekend.

Thanks for the above which works perfectly...I also modified it to identify and delete "dd inches"(where dd is a two digit numeric value) using the regex (\d\dinches) but this seems to have failed for some reason...I wondered if you might be able to suggest where I'm going wrong?

Thanks in advance.

Regards
Chris

Submitted by support on Mon, 2014-12-15 17:08

Hi Chris,

Use \s to match any sequence of white space e.g.

\d\d\sinches

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Mon, 2016-10-03 11:53

Great searchReplaceRegExp but how do I make multiple phrases case insensitive?

An example:
I wanted to replace this:
(DE 34|de 34|EU 34|eu 34|FR 36|fr 36|IT 40|it 40)

For this, but this doesn't work:
(de 34|eu 34|fr 36|it 40)/i

What is the correct syntax to use?

Submitted by support on Mon, 2016-10-03 12:00

Hi Marco,

You'd need delimiters both ends of the expression - have a go with;

/(de 34|eu 34|fr 36|it 40)/i

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Mon, 2016-10-03 12:12

Thank you.

Submitted by marco@flapper on Mon, 2016-10-03 14:00

Hi,
And what if there is a / in the phrase?

I have for example the phrase: "9 / 12 maanden" and want to replace that.

I tried this unsuccesfully
/(9 / 12 maanden)/i

Submitted by support on Mon, 2016-10-03 14:05

Hi Marco,

If your expression contains the delimiter character, then it needs to be escaped with "\" - have a go with;

/(9 \/ 12 maanden)/i

Cheers,
David.
--
PriceTapestry.com

Submitted by marco@flapper on Tue, 2016-10-04 07:43

Thank you

Submitted by Retro135 on Thu, 2016-12-29 04:13

Don't know if this is the filter I should be using for this situation, but trying it.

I'm having trouble figuring out how to create a regex to compare sale price vs price, and if the sale price is the same as the price, drop the sale price.

Submitted by support on Thu, 2016-12-29 11:34

Hi,

It's probably easiest to hard code this, and also gives an opportunity to decimalise the sale price value. Assuming you have used the field name "saleprice", in includes/admin.php look for the following code around line 465:

    /* decimalise price */
    $importRecord["price"] = tapestry_decimalise($importRecord["price"]);

...and REPLACE with:

    /* decimalise price */
    $importRecord["price"] = tapestry_decimalise($importRecord["price"]);
    $importRecord["saleprice"] = tapestry_decimalise($importRecord["saleprice"]);
    if ($importRecord["saleprice"]=="0.00" || ($importRecord["saleprice"]==$importRecord["price"]))
    {
      $importRecord["saleprice"] = "";
    }

Hope this helps!

Cheers,
David.
--
PriceTapestry.com

Submitted by Retro135 on Fri, 2016-12-30 13:16

David,
Never mind about the first part of my latest reply here about importing feeds taking longer. That was my error.