Find and replace in the Sniffie extension is a very useful tool to manipulate the data to your liking. Combined with column cloning and attribute extraction, it allows you to effectively get the data that you just need. The usefulness is increased if regular expressions (regex) are used for extracting tricky parts of data. Here are some of the most common examples.

How to extract EAN numbers out of any string

\d{13}

Here’s the breakdown of this regular expression:

  1. \d matches matches a digit. That is, this searches for any character between 0-9. Everything else is excluded.
  2. {13} is a quantifier. This forces the prepending attribute (any digit) to be matched exactly 13 times.

Running the above regex in the regex search field for e.g. href attribute like https://www.myexamplewebstore.com/thisisnotarealstore/i/6411720455548_1/192x192px will return 6411720455548 which represents the product’s EAN in this case. Different countries may use different EAN codes, but common for them is that they are 13 digits long.

What if the url would be https://www.anotherexample.com/a/6411720455548_1/8811720455548_1/1.png? You would get two matches, 6411720455548 and 8811720455548 by performing the above regular expression. You would then indicate which one you need by including $1 or $2 in the replace field in the extension. These represent the match groups: $1 will return 6411720455548 and $2 will return 8811720455548. If you need both, just clone the column multiple times and select $1 for the first one, $2 for the second. šŸ™‚

How to extract other product codes / SKUs with dashes

[\d-]{15}

Here’s the breakdown for this regular expression:

  1. [\d-] matches any digit or a dash character. Everything else is excluded.
  2. {15} is the quantifier.Ā This forces the prepending attributes (any digit or a dash character) to be matched consecutively exactly 15 times.

Running the above regex in the regex search field for e.g. href attribute likeĀ https://www.myexamplewebstore.com/thisisnotarealstore/i/641-720-555-481_1/192x192px will returnĀ 641-720-555-481 which represents the product code in this case. Depending on the length of the product code, you may need to change the quantifier value. Play around with it to see what works!

How to extract other product codes / SKUs with underscores

[\d_]{15}

Here’s the breakdown for this regular expression:

  1. [\d_] matches any digit or an underscore character. Everything else is excluded.
  2. {15} is the quantifier.Ā This forces the prepending attributes (any digit or a underscore character) to be matched consecutively exactly 15 times.

Running the above regex in the regex search field for e.g. href attribute likeĀ https://www.myexamplewebstore.com/thisisnotarealstore/i/641_720_555_481_1/192x192px will returnĀ 641_720_555_481 which represents the product code in this case. Note that the _1 is not part of the product code since the quantifier is only 15 characters! Depending on the length of the product code, you may need to change the quantifier value. Play around with it to see what works!

How to extract other product codes / SKUs with dashes and underscores

[\d_-]{15}

Here’s the breakdown for this regular expression:

  1. [\d_-] matches any digit, an underscore character or a dash character.
  2. {15} is the quantifier.Ā This forces the prepending attributes (any digit, a dash character or an underscore character) to be matched consecutively exactly 15 times.

Running the above regex in the regex search field for e.g. href attribute likeĀ https://www.myexamplewebstore.com/thisisnotarealstore/i/641_720-555_481_1/192x192px will returnĀ 641_720-555_481 which represents the product code in this case. Note that the _1 is not part of the product code since the quantifier is only 15 characters! Depending on the length of the product code, you may need to change the quantifier value. Play around with it to see what works!