you can use the ($result)= ($string=~ m/pattern/); idiom this way:
#!/usr/bin/perl -w use strict; while( my $string=<DATA>) { my( $domain)= ($string=~ m{(?:^|\.) # the beginning of the s +tring or . ([^.]*) # anything but . (and st +ore it in $1) \.com # .com (?:\/|$) # a / or the end of the s +tring }x); print "domain: $domain\n"; } __DATA__ l-12345.in.some.domain.com l-12345.in.some.domain.com/blargh/index.html domain.com/blargh/index.html domain.com domain.com/ l-12345.in.some.domain.com/blargh/foo.com nope.com.domain.com/blargh/foo.com l-12345.in.some.domain.com/blargh/nope.foo.com
In reply to Re: pattern matching
by mirod
in thread Creating a regex to match part of a URL's domain name (was: pattern matching)
by strfry()
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |