regex on Mikrotik RouterOS
image from

regex on Mikrotik RouterOS. Regex means regular expression. Is a feature / function to create pattern matcher. because of that capability regex is mostly used on Firewall, routing filter, and anything that is related to pattern matching.

So our main job here is to create a pattern and regex has its own symbols to define a pattern. one good page that explains list of regex pattern matcher can be found here.

Based on my experience, in order to make matchers the steps are:

  1. setup your purpose
  2. create matcher with your own language
  3. translate it to regex format

ok lets try…

  1. the purpose is to match url that contains youtube
  2. so the pattern would be:
    1. (separated by .)or
    2. (anything that contains youtube)
  3. well, the regex pattern would be
    1. ^.+\.youtube\..+$
    2. ^.*youtube.*\.com$

here’s the explanation:

  • ^ -> match the beginning of the string
  • . -> match any single character
  • + -> this is quatifier, that defines how many preceding character is repeated. + means 1 or any repetition
  • * -> this is quatifier as well. * means 0 or any repetition.
  • \. -> \ is an escape character to define (dot). otherwise will be confused with (.)
  • $ -> match end of string

OK hope you have some enlightenment on regex

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.