REGEX (or regular expression) is a way of specifying a pattern that you want present in a text. For example, if you are looking for socks, but you only want notifications on for ONLY "no show" or "athletic" socks, you can use expressions like:
(no show|athletic).*socks
Another example: "gummies" will show search results for all gummies: snacks and health supplements. But if you use expressions like:
(haribo|vegan).*gumm
You can specify that you only want haribo gummies or vegan gummies. This will stop you from getting notifications from multivitamin gummies, apple cider vinegar gummies, etc. Another example would be:
"wom[ae]n"
or
(woman|women)
If you want notifications for items that contain woman or women but may not necessarily have both keywords in the title at same time.
For more information and to test your Regex, you can use:
Again, Regex 101 will be an immense help to test out your keywords!
Regular expression use a special syntax to define a pattern for complex search. Here are some of the basic syntax to get you started:
()
can be used to group words or letters, just just delimite your logic as regular () do in mathematics for example.[]
serve to define a list of characters, to be considered individually.|
means orExamples:
wom[ea]n
will match woman
and women
.plush(y|ies)
will match plushy
or (|
) plushies
.?
means 0 or 1 time+
means 1 or more time*
means 0 or more timeExamples:
speaker[s]?
will match speaker
or speakers
pants [x]+l
will match pants xl
, pants xxl
, pants xxxl
, etc.(really )*(good)
will match good
, really good
, really really good
, etc.\
in front of it..
means any character\s
means a space character\b
define a word boundary (the beginning or end of a word)^
represent the beginning of the text$
represent the end of the textExamples:
laptop(.*)adapter
, would match laptop 12V 3A adapter
hair[\s]?band
, would match hair band
or hairband
\(12\)
, would match (12)
\bapple\b
would match an apple tree
but not applebee
^ancient
would match ancient worlds
but not the ancient world
dog$
would match a big dog
, but not a dog bite
Fair warning: look ahead, look behind and their negative counterparts can get complicated quickly and can be finicky to get to work. Use regex101.com if you plan on crafting one of those and run extensive scenarios to ensure it behave as you expect.
?=
at the beginning of a group, indicate a positive lookahead operation, meaning we want the regex to scan the entire expression forward to try to match the parameters that follows.
?!
at the beginning of a group, indicate a negative lookahead operation, meaning that in order for the regex to match, we want for the following parameters not to match.
?<=
positive look behind. Do not use this unless you hate yourself.
?<!
negative look behind. Do not use this unless you hate yourself.
Example:
^(?=.*\b(laptop|notebook)\b)(?!.*\b(cable|adapter)\b).*
will match all the results matching laptop
or notebook
which do not contain the words cable
or adapter
.
Why do we need to start with
^
and use.*
immediately after the look ahead parameters as well as at the very end of the expression?
Because otherwise the regex will be allowed to run on part of the text only. Forcing it to start at the beginning ensure all the text is processed, which makes.*
required as the text may not start (or end) with the keyword we are looking for.
Look ahead and negative look ahead are an advanced skill and are not easy or intuitive to implement.
[hc]at
, matches "hat" and "cat".
[^b]at
, matches all texts matched by .at except "bat".
\btable\b
, matches the word table, but does not match portable (because of word boundary).
^(?!.*car).*battery
, matches battery when car is not present anywhere
^(?=.*bed).*\b(king|queen)\b
, matches king or queen (with word boundary) when bed is present somewhere