User Tools

Site Tools


profimail:regex

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

profimail:regex [2013/03/05 14:13]
profimail:regex [2019/07/16 20:26] (current)
Line 1: Line 1:
 +===== Regular expressions =====
  
 +What are regular expressions? In short, this is syntax for flexible matching of text (searching elements inside of text) by writing a formula with wild-cards and patterns.
 +
 +Learn more here: [[wp>Regex]]
 +
 +What are Regular expressions good for in ProfiMail? They may be used in [[.:rules|Rules]] for writing Rule condition to match text (for example in message subject or header).
 +
 +Here is good online regex tester for playing with: [[http://www.regexpal.com|www.regexpal.com]]
 +
 +==== Quick reference to regex syntax ====
 +
 +
 +|.|Any character ((except newline))|
 +|\.|period ((\ escapes also other characters such as: \* \( \\\\ ))|
 +|%%^%%|start of string|
 +|$|end of string|
 +|\d, \w, \s|digit, word character [A-Za-z0-9_], or whitespace|
 +|\D, \W, \S|anything except digit, word character, or whitespace|
 +|[abc]|character a, b, or c ((matches any character that is included in brackets))|
 +|[a-z]|a through z ((matches any character that is in given range of characters))|
 +|[%%^%%abc]|any character except a, b, or c|
 +|aa%%|%%bb|either aa or bb|
 +|?|zero or one of preceding element|
 +|*|zero or more of preceding element|
 +|+|one or more of preceding element|
 +|{n}|exactly n times of preceding element|
 +|{n,}|n or more times of preceding element|
 +|{m,n}|between m and n times of preceding element|
 +|??, *?, +?, {n}?|same as above, but as few as possible|
 +|(expr)|capture expr for use with \1, etc|
 +|(?:expr)|non-capturing group|
 +|(?=expr)|followed by expr|
 +|(?!expr)|not followed by expr|
 +
 +
 +
 +==== Simple example ====
 +
 +For example, you may want to create a Rule to find messages sent from //josh@example.com// or from //mary@example.com//. You could write separate Rule condition with all possible email addresses to search for, or you can use regular expression:
 +
 +   (josh|mary)@example.com
 +
 +Which means to search for text that begins with //josh// OR //mary// followed by //@example.com//.
 +
 +To extend the example, here is formula to match any email address from //@example.com// domain:
 +
 +   \w+@example.com
 +
 +That means any word character occurring one or more time before text //@example.com//.
 +
 +For the rest, you can make your own tests in this [[http://www.regexpal.com|online tester]], or try this in [[.:activity:rules_editor|Rules]].