Regex to remove number and sign '/' before or after '/' if less than 20 in productfeed attribute

102 Views Asked by At

We have created a product feed from a Magento webshop using the Koongo Module. We want to submit this feed to a marketplace. Our customer does not consistently fill in the size field when adding products. As a result, there is also an incorrect format for the marketplace. Size examples are: 39/6 or 40 / 6.5 or 8/42 or 8.5 / 42.5. In short, either first the European size and then the UK size or first the UK size and then the European size. We want to correctly display the size in the feed using a regular expression, namely only the European size. In short, we no longer want to include either '/ UK m' or 'UK size /'. It is important that the sign / must also be removed from the outcome in our product feed. Can you help?

We have the option to fill in two fields, namely 'Rewrite from' and 'Rewrite to'. We can use a regular expression for each of these fields.

Thanks in advance for the help.

2

There are 2 best solutions below

1
alf_gralf On

It would be simple to only take the numbers >= 20. Does that help you?

[2-5][0-9](\.5)?

This will match all sizes between 20 and 59 with the option of half sizes

0
Peter Thoeny On

I am not familiar with Magento. If it supports regular expression replace with capture groups try this:

  • Rewrite From: ^.*?([234][0-9](\.5)?).*?$
  • Rewrite To: $1

Explanation:

  • ^ - anchor at start of string
  • .*? - non-greedy scan
  • ( - capture group start
    • [234][0-9] - number between 20 and 49
    • (\.5)? - optional .5 fraction
  • ) - capture group end
  • .*? - non-greedy scan
  • $ - anchor at end of string
  • use capture group in replace: $1