About regular expressions
About regular expressions
August 7, 2024
ID 260696
Regular expressions are used to filter message content when setting general filtering options and conditions. General information about regular expressions can be found on the Microsoft website at: Regular Expressions Reference.
Optimizing regular expressions
You can optimize regular expressions to prevent backtracking that interferes with string matching, and to time out operations.
To optimize regular expressions, you must adhere to the following rules:
- Use possessive quantifiers (++, *+).
- If possible, use non-matching group (?:) with outer brackets.
- Try to use alternation as little as possible and find matches at the end of the string. The alternation operator has the lowest precedence of all regular expression operators.
- Use anchors (^, $) that match the start and end positions in the string.
- Use atomic groups. Atomic groups automatically discard any backtracking positions memorized by any tokens within the group. The syntax is (?> ...).
- In long regular expressions, try to avoid exponentially increasing the amount of backtracking. An example such as (qwerty.*)* is not recommended.
Did you find this article helpful?
What can we do better?
Thank you for your feedback! You're helping us improve.
Thank you for your feedback! You're helping us improve.