We help IT Professionals succeed at work.

domain regex

hi,

i'd like to Match URLs for specific domain with the following terms:

example:

search.casper.com -> must exists in url
xxx.search.casper.com -> false
search.casper.com\xxx -> false
search.casper.com  -> false
xxx.search.casper.com\xxxx -> true


--> xxx referes to  [a-A,0-9]
--> any [a-A,0-9] is allowed prior 'search' only if .com is followed by slash and  [a-A,0-9]
--> all other cases should be not match.

cheers.




Comment
Watch Question

CERTIFIED EXPERT
Commented:
\[a-zA-Z0-9]+\.search\.casper\.com[\\\/][a-A,0-9]+
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
Be sure to remove the leading backslash from farzanj's suggestion as it actually makes the pattern itself un-parsable  = )
CERTIFIED EXPERT

Commented:
Yes, I don't know how that got in there.  Thanks Kaufmed.
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
I did have one question, though. For this requirement:

    * any [a-A,0-9] is allowed prior 'search' only if .com is followed by slash and  [a-A,0-9]

Which, if any or if all, of the following are good results:

    help.search.casper.com/help
    help.search.casper.com/somepage
Terry WoodsWeb Developer, specialising in WordPress
CERTIFIED EXPERT
Most Valuable Expert 2011
Commented:
And if you also want to allow the following:
blah.help.search.casper.com/help
help.search.casper.com/help/blah
rhubarb.blah.help.search.casper.com/help
etc

Then you can use:
([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+\.search\.casper\.com[\\/][a-A,0-9]+(/[a-A,0-9]+)*

(Acknowledgement: I built on farzanj's pattern)
Meir RivkinFull stack Software Engineer
CERTIFIED EXPERT

Author

Commented:
thanks for your comments.
i'm using this pattern to create black/white lists for my needs.

for instance my black list is:
@"([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+\.search\.casper\.com[\\/][a-zA-Z0-9]+(/[a-zA-Z0-9]+)*",

and white list is:
@"lab+\.search\.casper\.com[\\/][a-zA-Z0-9]+(/[a-zA-Z0-9]+)*",

the problem is that this url is matched and it shouldn't:
hp.lab.search.casper.com\labs -> currently returns true
xxxlab.search.casper.com\xxx -> should return false


how to change the white list pattern to allow just the subdomain prior 'search.casper.com',
so nothing can come before lab.search.casper.com?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.