Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Match domain names except one

by Anonymous Monk
on Feb 13, 2013 at 07:42 UTC ( #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.

Comment on Match domain names except one
Select or Download Code
Re: Match domain names except one
by kcott (Abbot) 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 Anonymous Monk on Feb 13, 2013 at 07:57 UTC
Re: Match domain names except one
by vinoth.ree (Parson) 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

        Thanks. But we need it in a regex

        Maybe you can write 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.

Re: Match domain names except one
by BillKSmith (Chaplain) 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
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? | Other CB clients
Other Users?
Others examining the Monastery: (12)
As of 2014-07-31 21:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (253 votes), past polls