Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Match domain names except one

by Anonymous Monk
on Feb 13, 2013 at 07:42 UTC ( [id://1018491]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Input https://www.abc.com.wi.pr.com/ https://www.abc.com/ https://www.def.com.wi.pr.com/ https://www.wt.com.wi.pr.com/

There are many URL's but we should not match with the string (wt).

https?://(www.)?(abc|def).com[^/]*/?$

Hard coding works but there are many names which is not possible,

Trying to use the regex something like this but no luck :(
https?://(www.)?(.*)(?!wt).com[^/]*/?$
Please help me.

Replies are listed 'Best First'.
Re: Match domain names except one
by kcott (Archbishop) on Feb 13, 2013 at 07:56 UTC
    "There are many URL's but we should not match with the string (wt)."

    The following solves your problem - as stated.

    $ perl -Mstrict -Mwarnings -E ' my @urls = qw{ https://www.abc.com.wi.pr.com/ https://www.abc.com/ https://www.def.com.wi.pr.com/ https://www.wt.com.wi.pr.com/ }; for (@urls) { say unless /wt/; } ' https://www.abc.com.wi.pr.com/ https://www.abc.com/ https://www.def.com.wi.pr.com/

    I suspect your problem is more complex. If so, please provide more complete details of your requirements; if not, enjoy. :-)

    -- Ken

Re: Match domain names except one
by vinoth.ree (Monsignor) on Feb 13, 2013 at 08:02 UTC
    should not match with the string (wt)

    If you do not want to match wt string directly check for unless /\.wt\./ and print.

    use strict; use warnings; use utf8; while(<DATA>) { unless(/\.wt\./) { print "matches : $_\n"; } } __DATA__ https://www.abc.com.wi.pr.com/ https://www.abc.com/ https://www.def.com.wi.pr.com/ https://www.wt.com.wi.pr.com/
      Thanks. But we need it in a regex

        What strange business requirement indicates that you "need it in a regex"?

        ...roboticus

        When your only tool is a hammer, all problems look like your thumb.

        Well then, I have some excellent news for you: /\.wt\./ is a regex.

        Thanks. But we need it in a regex

        Maybe you can write a regex

Re: Match domain names except one
by Anonymous Monk on Feb 13, 2013 at 07:57 UTC
Re: Match domain names except one
by BillKSmith (Monsignor) on Feb 13, 2013 at 14:20 UTC

    There is nothing in perl preventing you from using two regular expressions. Perhaps you could use the vinoth.ree suggestion to remove unwanted results that are not removed by your own regex.

    Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1018491]
Approved by vinoth.ree
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-24 01:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found