Pattern Matching -- Advanced Knowledge

Yes, it's somewhat of an advanced topic - Don't panic, though .. it's not that bad.

Use this to create patterns for matching items to rules in your repricing scripts such as Exclusions, for example.   

"A regular expression (abbreviated as regexp, regex, or regxp, with plural forms regexps, regexes, or regexen) is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns. Many programming languages support regular expressions for string manipulation. For example, Perl and Tcl have a powerful regular expression engine built directly into their syntax. The set of utilities (including the editor sed and the filter grep) provided by Unix distributions were the first to popularize the concept of regular expressions." - Wikipedia

Anywhere in AOB that you see a reference to a 'pattern search', we're also talking about regular expressions.

I can hear it now .. "That's fine, Rodger .. in English, please."

A regular expression is a method by which you can 'match' a text 'pattern'.   Let me throw out some examples:

*Let's say you want to match strings (maybe a SKU, your notes, etc.) that start with 'BR5' (you're on the repricing configuration page, and you want to exclude all items with SKUs starting with 'BR5'). The pattern would be


See the '^'? That's a 'beginning anchor'. It anchors the search to the beginning of the string. BR549 would match, but 1-BR549 would not.

*Let's say you want to match strings that end with 'where'. The pattern would be


See the '$'? That's an 'ending anchor'. It anchors the search to the end of the string. 'somewhere' would match, but 'somewhereelse' would not.

*You can combine the anchors, too.


would match the string 'where' and that's it.

But, if you just use the string you're looking for with no modifiers or anchors, then that string can match anywhere. For example.. the pattern


would match 'somewhere', 'somewhereelse', and 'where with all'.


There are some special characters you should be aware of. For any of these 'special characters', you should put a '\' before the character to get it to be treated as that character. Here are some common ones:

To use a literal .. Use this.. Because that character really means this w/o the backslash..
. \. Match ANY SINGLE character
- \- Match a RANGE of characters
( or ) \( or \) Used in 'backreferences' .. don't worry about it
[ or ] \[ or \] Used in creating character 'classes'
+ * or ? \+ \* or \? Used in defining multi-character matches

For 90% of the cases, you can stop here as the 3 forms above are all you'll ever need (matching at the beginning, ending, or anywhere in between.

The possibilities for pattern-matching are nearly limitless, so if you need to match something in one of your scripts and can't figure out how to do it leave us a comment and let us know.  We'll be glad to update and let everyone else know too.  

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request


Powered by Zendesk