Good to hear. You do kinda have to test them, since RouterOS has its own flavor. I kinda knew the ?! was likely not going work here.
But \D \w etc stuff I’m not sure about… and seemingly the 3rd problem here (1st being the lack of escaped “$”, 2nd the “?!” does not work) since OP using the [A-z] style…
While those work “standalone”, RouterOS does not seem to process them in a character class. Maybe this right in some flavor, but these should be “true” IMO:
I already pulled my hair out because of this limited POSIX regex implemention of ROS. In my case, make it very hard to impossible to write a regex for FWD for any subdomain except not matching 2 explicit 3rd Level Domains. Easy with negative lookahead, but Mikrotik likes us to suffer.
This is my first time using MK regex… I think I finally solve this puzzle.
As I have a script updating dns static on dhcp leasing, I need to make a small change. Previously I has DNS static using this domain: WORD-XX.ad.localdomain. The machine/printer name still the same, for example: SALES-01, SALES-02, etc., but I was made a change in the domain. Now all my lan computers will following this new standard: WORD-XX.LAN.AD.LOCALDOMAIN.
So I have changed the FWD regex to: (\.*[^lan|^wlan]\.ad\.localdomain$|^ad\.localdomain$)
Important: to debug, I have to use \ on terminal… but on regex you have to remove ALL \ and \ to get it working.
So, just use: .*[^lan|^wlan].ad.localdomain$|^ad.localdomain$
Any request to ad.localdomain or subdomains.ad.localdomain will be forwarded to AD DNS, except records with lan and wlan in the host, that in my case, represents clients using lan (cabled and wifi) that must be forwarded to MK.
I also implemented a DNS check in netwatch that, in case of timeout of my AD, I just disable the static DNS regex.
Well, that does make it easy and likely okay. But “.” still means any character to the regex. While improbable, lan1ad.localdomain would match the domain parts. Not say it’s critical, but \. is there for a reason, since you want match the literal “.”.
To the “ripping your hair out” commentary, apparently inside the [character class], the . is literal.. which might be right, IDK. But that avoid needing escaping things between RouterOS and some other regex parser, like regex101.com.