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:
- setup your purpose
- create matcher with your own language
- translate it to regex format
ok lets try…
- the purpose is to match url that contains youtube
- so the pattern would be:
- xxx.youtube.xxx (separated by .)or
- XXXyoutubeXXX.com (anything that contains youtube)
- well, the regex pattern would be
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