Results 1 to 2 of 2
I'm working on a regular expression using the Perl engine. I need a regex that matches a domain, when the pattern precedes the Top Level Domain. I thought I had ...
- 10-03-2008 #1Just Joined!
- Join Date
- Jun 2008
- Posts
- 10
Match pattern in specific part of domain
I'm working on a regular expression using the Perl engine. I need a regex that matches a domain, when the pattern precedes the Top Level Domain. I thought I had the problem fixed up just fine with this regex:
That regex matches imagesstock.com & coolimages.net, etc, but doesn't match dell.com/foimages/laptop.html, etc. That's working mighty fine.Code:^[^/]*images
However, the regex shown above DOES match subdomains images.tigerdirect.com, and I hadn't intended those subdomains to match.
What is the correct syntax to match:
imagesstock.com
coolimages.net
But skip
dell.com/foimages/laptop.html AND
images.tigerdirect.com
I had triedbut the [] are giving alteration behavior instead of grouping. I think that regex would work if I could just find the syntax to group \.*\. into one pattern.Code:^[^/]*images[^\.*\.] and ^[^/]*images[^(\.*\.)]
Thanks a million for any ideas you might have.
- 10-03-2008 #2
I'm assuming you also want to accept as valid:
imagesstock.com/asdf.html
Try this Perl script, adjusting the top line to match the path to perl on your system:
Hope this helps.Code:#!/usr/bin/perl while($in_line=<STDIN>) { chomp($in_line); if($in_line=~/^[^\/]*images[^\/\.]*\.[a-z0-9]{2,4}(\/.*)?$/) { print "yes\n"; } else { print "no\n"; } }--
Bill
Old age and treachery will overcome youth and skill.


Reply With Quote