Put me out of my regexing misery.
June 21, 2012 2:31 PM Subscribe
I need a regex that will recursively match anything after a forward slash to the end of a URL.
posted by dozo to Computers & Internet (15 answers total) 1 user marked this as a favorite
I have a Wordpress site and I'm trying to redirect anyone trying to access one directory (and anything below that directory) that is not logged in to an error page. I have domain.com/docs/ and would like for /docs/phone or /docs/tech/office or /docs/a/b/c/90-07/gumball-snake-hugger - no matter how deep - to be redirected to a login/error page.
I'm using the super great Redirection plugin
to do some other basic redirections, and thought I would take advantage of the regex ability to do this seemingly simple task. I assumed a /docs/* would work but nooooooo. I've tried /docs/[a-z0-9-]* which is close but redirects in a way that Firefox tells me will never work on some of the URLs. I've tried the Wordpress forums but have found nothing helpful and no answer to my post - it seems the prevailing answer is to "Just learn regex". I've tried $(.*[\\\/]) and [^/]+$ to no avail. I've tried building one with several "easy regex builders" but they didn't work either.
Can someone please help me with a regex that will match anything that a URL could possibly be? If there is a another way for me to achieve this end I would be open to that as well.