All Products
Search
Document Center

How do I optimize regular expressions?

Last Updated: Sep 27, 2020

Introduction

When Log service uses full regex mode, you can optimize the regular expression to improve the log collection performance.

Background

For how to optimize regular expressions, we provide you with the following suggestions.

  • Use more accurate characters: Do not use blindly. *To match Fields. This expression contains a large search range, which is prone to mismatches. In addition, the matching performance will be reduced. If the field to be extracted consists of only letters, use the [A-Za-z] match.
  • Use correct quantifiers: Do not use blindly +and *. For example, using \d to match the IP address, then compare the \d+ for example, \d{1,3} could be better.
  • Debugging multiple times: Debugging is similar to troubleshooting. You can debug your regular expression on the regex101 website to optimize the problem in a timely manner.

 

Application scope

  • Log Service for WAF