I'm trying to get the following into a regex:
*.foo.com/*
success test cases
- www.foo.com
- www.foo.com/blah
- aaa.www.foo.com/woot/woot/woot
failure cases
- 开发者_StackOverflow
- www.blah.com
- blah.com/ruroh
How would I write a regex to do this?
A literal translation of your glob into regex is:
.*\.foo\.com(/.*)?
This should work, if you mean to test the sub-domains for foo.com:
/(?<part>(w(?!ww)|w(?=[a-z0-9]{3,})|[a-vx-z0-9])[a-z0-9]*)\.foo\.com/
I have an easy regex that works:
(.*)\.foo\.com
You can easily test a regular expression yourself using rubular. I strongly recommend it.
精彩评论