I am trying to build a regex to help me parse lots of robots.txt files. I am trying to find if specific user-agents have been disallowed.
Files look roughly like his but can vary a bit with whitepace:
User-agent: *
Disallow: /next/
User-agent: *
Disallow: /mshots/v1/
# har har
User-agent: *
Disallow: /activate/
User-agent: *
Disallow: /wp-login.php
User-agent: *
Disallow: /signup/
User-agent: *
Disallow: /related-tags.php
So far I have come up with this regex:
user-agent.*:(.*$)
With options set for multiline and ignorecase.
This works great for the user-agent part of my requirement but now I need to match any dissallow word that comes before another user-agent is declared. I have tried matching $ and \r\n but I can't figure out how to keep the match going after the $. Any pattern I add after doesn't seem to work. For instance:
user-agent.*:(.*$)(^.*disallow)
I am trying to match the newline and then dissallow but it doesn't match. Also I am not sure how to terminate the match before the user-agent and still work on last declaard rule.
Can anyone point me in right direction?