How to ignore all after domain zone except symbol “/”












1














I have regex for match domain with username:



/(?:https://)?(?:http://)?(?:www.)?(?:facebook).com/(w+(?:.w+)*)$/


This regex match example URLs:



facebook.com/username
www.facebook.com/username
http://facebook.com/username
http://www.facebook.com/username
https://facebook.com/username
https://www.facebook.com/username


How change this regex for match only URLs with domain zone and non required symbol /:



facebook.com
facebook.com/
.....................
https://facebook.com/
https://www.facebook.com









share|improve this question






















  • So you are wanting to match string that only have the domain, with no forward slash at the end?
    – K.Dᴀᴠɪs
    Nov 23 '18 at 5:56












  • @K.Dᴀᴠɪs Only domain name with or without slash
    – Andreas Hunter
    Nov 23 '18 at 5:57










  • Can you more clearly show which of the above 6 URLs should match, and then explain why that is the case?
    – Tim Biegeleisen
    Nov 23 '18 at 5:59






  • 1




    And is this for Perl or PCRE? You've tagged both, but they are different things
    – ikegami
    Nov 23 '18 at 6:00










  • If I understand you correctly, this should work ^(?:https?://)?(?:www.)?facebook.com/?$
    – K.Dᴀᴠɪs
    Nov 23 '18 at 6:01
















1














I have regex for match domain with username:



/(?:https://)?(?:http://)?(?:www.)?(?:facebook).com/(w+(?:.w+)*)$/


This regex match example URLs:



facebook.com/username
www.facebook.com/username
http://facebook.com/username
http://www.facebook.com/username
https://facebook.com/username
https://www.facebook.com/username


How change this regex for match only URLs with domain zone and non required symbol /:



facebook.com
facebook.com/
.....................
https://facebook.com/
https://www.facebook.com









share|improve this question






















  • So you are wanting to match string that only have the domain, with no forward slash at the end?
    – K.Dᴀᴠɪs
    Nov 23 '18 at 5:56












  • @K.Dᴀᴠɪs Only domain name with or without slash
    – Andreas Hunter
    Nov 23 '18 at 5:57










  • Can you more clearly show which of the above 6 URLs should match, and then explain why that is the case?
    – Tim Biegeleisen
    Nov 23 '18 at 5:59






  • 1




    And is this for Perl or PCRE? You've tagged both, but they are different things
    – ikegami
    Nov 23 '18 at 6:00










  • If I understand you correctly, this should work ^(?:https?://)?(?:www.)?facebook.com/?$
    – K.Dᴀᴠɪs
    Nov 23 '18 at 6:01














1












1








1







I have regex for match domain with username:



/(?:https://)?(?:http://)?(?:www.)?(?:facebook).com/(w+(?:.w+)*)$/


This regex match example URLs:



facebook.com/username
www.facebook.com/username
http://facebook.com/username
http://www.facebook.com/username
https://facebook.com/username
https://www.facebook.com/username


How change this regex for match only URLs with domain zone and non required symbol /:



facebook.com
facebook.com/
.....................
https://facebook.com/
https://www.facebook.com









share|improve this question













I have regex for match domain with username:



/(?:https://)?(?:http://)?(?:www.)?(?:facebook).com/(w+(?:.w+)*)$/


This regex match example URLs:



facebook.com/username
www.facebook.com/username
http://facebook.com/username
http://www.facebook.com/username
https://facebook.com/username
https://www.facebook.com/username


How change this regex for match only URLs with domain zone and non required symbol /:



facebook.com
facebook.com/
.....................
https://facebook.com/
https://www.facebook.com






regex string perl pcre






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 23 '18 at 5:53









Andreas Hunter

740418




740418












  • So you are wanting to match string that only have the domain, with no forward slash at the end?
    – K.Dᴀᴠɪs
    Nov 23 '18 at 5:56












  • @K.Dᴀᴠɪs Only domain name with or without slash
    – Andreas Hunter
    Nov 23 '18 at 5:57










  • Can you more clearly show which of the above 6 URLs should match, and then explain why that is the case?
    – Tim Biegeleisen
    Nov 23 '18 at 5:59






  • 1




    And is this for Perl or PCRE? You've tagged both, but they are different things
    – ikegami
    Nov 23 '18 at 6:00










  • If I understand you correctly, this should work ^(?:https?://)?(?:www.)?facebook.com/?$
    – K.Dᴀᴠɪs
    Nov 23 '18 at 6:01


















  • So you are wanting to match string that only have the domain, with no forward slash at the end?
    – K.Dᴀᴠɪs
    Nov 23 '18 at 5:56












  • @K.Dᴀᴠɪs Only domain name with or without slash
    – Andreas Hunter
    Nov 23 '18 at 5:57










  • Can you more clearly show which of the above 6 URLs should match, and then explain why that is the case?
    – Tim Biegeleisen
    Nov 23 '18 at 5:59






  • 1




    And is this for Perl or PCRE? You've tagged both, but they are different things
    – ikegami
    Nov 23 '18 at 6:00










  • If I understand you correctly, this should work ^(?:https?://)?(?:www.)?facebook.com/?$
    – K.Dᴀᴠɪs
    Nov 23 '18 at 6:01
















So you are wanting to match string that only have the domain, with no forward slash at the end?
– K.Dᴀᴠɪs
Nov 23 '18 at 5:56






So you are wanting to match string that only have the domain, with no forward slash at the end?
– K.Dᴀᴠɪs
Nov 23 '18 at 5:56














@K.Dᴀᴠɪs Only domain name with or without slash
– Andreas Hunter
Nov 23 '18 at 5:57




@K.Dᴀᴠɪs Only domain name with or without slash
– Andreas Hunter
Nov 23 '18 at 5:57












Can you more clearly show which of the above 6 URLs should match, and then explain why that is the case?
– Tim Biegeleisen
Nov 23 '18 at 5:59




Can you more clearly show which of the above 6 URLs should match, and then explain why that is the case?
– Tim Biegeleisen
Nov 23 '18 at 5:59




1




1




And is this for Perl or PCRE? You've tagged both, but they are different things
– ikegami
Nov 23 '18 at 6:00




And is this for Perl or PCRE? You've tagged both, but they are different things
– ikegami
Nov 23 '18 at 6:00












If I understand you correctly, this should work ^(?:https?://)?(?:www.)?facebook.com/?$
– K.Dᴀᴠɪs
Nov 23 '18 at 6:01




If I understand you correctly, this should work ^(?:https?://)?(?:www.)?facebook.com/?$
– K.Dᴀᴠɪs
Nov 23 '18 at 6:01












2 Answers
2






active

oldest

votes


















1














You are only wanting to match strings that contain the domain only, then you can use something like this:



^(?:https?://)?(?:www.)?facebook.com/?$


This will match regardless if it has the protocol (http(s)://) and regardless if it contains www..



See it live



Breaking down the regular expression, ^(?:https?://)?(?:www.)?facebook.com/?$





  • ^ start of string


  • (?:https?://)? a non-capturing group that will match the protocol https?://, zero or one time ? (optional)


  • (?:www.)? non-capturing group that will match on www., zero or one time ? (optional)


  • facebook.com will match the domain


  • /? will match an optional ? forward slash /


  • $ end of string (emphasis added) - this is what allows this to work with your requirements as this will not allow anything to match after the optional forward slash in the prior bullet.






share|improve this answer























  • Thanks @K.Dᴀᴠɪs. This regex work for me.
    – Andreas Hunter
    Nov 23 '18 at 6:06





















2














Since this is tagged Perl, a Perl answer is to use a URI-parsing module such as URI or Mojo::URL.



use strict;
use warnings;
use Mojo::URL;
while (my $input = <<>>) { # or whatever way the input comes in
chomp $input;
my $url = Mojo::URL->new($input);
next unless !defined $url->scheme or $url->scheme eq 'http' or $url->scheme eq 'https';
next unless defined $url->host and ($url->host eq 'facebook.com' or $url->host eq 'www.facebook.com');
next if length $url->path and $url->path ne '/';
print "$inputn";
}





share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441280%2fhow-to-ignore-all-after-domain-zone-except-symbol%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You are only wanting to match strings that contain the domain only, then you can use something like this:



    ^(?:https?://)?(?:www.)?facebook.com/?$


    This will match regardless if it has the protocol (http(s)://) and regardless if it contains www..



    See it live



    Breaking down the regular expression, ^(?:https?://)?(?:www.)?facebook.com/?$





    • ^ start of string


    • (?:https?://)? a non-capturing group that will match the protocol https?://, zero or one time ? (optional)


    • (?:www.)? non-capturing group that will match on www., zero or one time ? (optional)


    • facebook.com will match the domain


    • /? will match an optional ? forward slash /


    • $ end of string (emphasis added) - this is what allows this to work with your requirements as this will not allow anything to match after the optional forward slash in the prior bullet.






    share|improve this answer























    • Thanks @K.Dᴀᴠɪs. This regex work for me.
      – Andreas Hunter
      Nov 23 '18 at 6:06


















    1














    You are only wanting to match strings that contain the domain only, then you can use something like this:



    ^(?:https?://)?(?:www.)?facebook.com/?$


    This will match regardless if it has the protocol (http(s)://) and regardless if it contains www..



    See it live



    Breaking down the regular expression, ^(?:https?://)?(?:www.)?facebook.com/?$





    • ^ start of string


    • (?:https?://)? a non-capturing group that will match the protocol https?://, zero or one time ? (optional)


    • (?:www.)? non-capturing group that will match on www., zero or one time ? (optional)


    • facebook.com will match the domain


    • /? will match an optional ? forward slash /


    • $ end of string (emphasis added) - this is what allows this to work with your requirements as this will not allow anything to match after the optional forward slash in the prior bullet.






    share|improve this answer























    • Thanks @K.Dᴀᴠɪs. This regex work for me.
      – Andreas Hunter
      Nov 23 '18 at 6:06
















    1












    1








    1






    You are only wanting to match strings that contain the domain only, then you can use something like this:



    ^(?:https?://)?(?:www.)?facebook.com/?$


    This will match regardless if it has the protocol (http(s)://) and regardless if it contains www..



    See it live



    Breaking down the regular expression, ^(?:https?://)?(?:www.)?facebook.com/?$





    • ^ start of string


    • (?:https?://)? a non-capturing group that will match the protocol https?://, zero or one time ? (optional)


    • (?:www.)? non-capturing group that will match on www., zero or one time ? (optional)


    • facebook.com will match the domain


    • /? will match an optional ? forward slash /


    • $ end of string (emphasis added) - this is what allows this to work with your requirements as this will not allow anything to match after the optional forward slash in the prior bullet.






    share|improve this answer














    You are only wanting to match strings that contain the domain only, then you can use something like this:



    ^(?:https?://)?(?:www.)?facebook.com/?$


    This will match regardless if it has the protocol (http(s)://) and regardless if it contains www..



    See it live



    Breaking down the regular expression, ^(?:https?://)?(?:www.)?facebook.com/?$





    • ^ start of string


    • (?:https?://)? a non-capturing group that will match the protocol https?://, zero or one time ? (optional)


    • (?:www.)? non-capturing group that will match on www., zero or one time ? (optional)


    • facebook.com will match the domain


    • /? will match an optional ? forward slash /


    • $ end of string (emphasis added) - this is what allows this to work with your requirements as this will not allow anything to match after the optional forward slash in the prior bullet.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 23 '18 at 6:06

























    answered Nov 23 '18 at 6:03









    K.Dᴀᴠɪs

    6,956112239




    6,956112239












    • Thanks @K.Dᴀᴠɪs. This regex work for me.
      – Andreas Hunter
      Nov 23 '18 at 6:06




















    • Thanks @K.Dᴀᴠɪs. This regex work for me.
      – Andreas Hunter
      Nov 23 '18 at 6:06


















    Thanks @K.Dᴀᴠɪs. This regex work for me.
    – Andreas Hunter
    Nov 23 '18 at 6:06






    Thanks @K.Dᴀᴠɪs. This regex work for me.
    – Andreas Hunter
    Nov 23 '18 at 6:06















    2














    Since this is tagged Perl, a Perl answer is to use a URI-parsing module such as URI or Mojo::URL.



    use strict;
    use warnings;
    use Mojo::URL;
    while (my $input = <<>>) { # or whatever way the input comes in
    chomp $input;
    my $url = Mojo::URL->new($input);
    next unless !defined $url->scheme or $url->scheme eq 'http' or $url->scheme eq 'https';
    next unless defined $url->host and ($url->host eq 'facebook.com' or $url->host eq 'www.facebook.com');
    next if length $url->path and $url->path ne '/';
    print "$inputn";
    }





    share|improve this answer


























      2














      Since this is tagged Perl, a Perl answer is to use a URI-parsing module such as URI or Mojo::URL.



      use strict;
      use warnings;
      use Mojo::URL;
      while (my $input = <<>>) { # or whatever way the input comes in
      chomp $input;
      my $url = Mojo::URL->new($input);
      next unless !defined $url->scheme or $url->scheme eq 'http' or $url->scheme eq 'https';
      next unless defined $url->host and ($url->host eq 'facebook.com' or $url->host eq 'www.facebook.com');
      next if length $url->path and $url->path ne '/';
      print "$inputn";
      }





      share|improve this answer
























        2












        2








        2






        Since this is tagged Perl, a Perl answer is to use a URI-parsing module such as URI or Mojo::URL.



        use strict;
        use warnings;
        use Mojo::URL;
        while (my $input = <<>>) { # or whatever way the input comes in
        chomp $input;
        my $url = Mojo::URL->new($input);
        next unless !defined $url->scheme or $url->scheme eq 'http' or $url->scheme eq 'https';
        next unless defined $url->host and ($url->host eq 'facebook.com' or $url->host eq 'www.facebook.com');
        next if length $url->path and $url->path ne '/';
        print "$inputn";
        }





        share|improve this answer












        Since this is tagged Perl, a Perl answer is to use a URI-parsing module such as URI or Mojo::URL.



        use strict;
        use warnings;
        use Mojo::URL;
        while (my $input = <<>>) { # or whatever way the input comes in
        chomp $input;
        my $url = Mojo::URL->new($input);
        next unless !defined $url->scheme or $url->scheme eq 'http' or $url->scheme eq 'https';
        next unless defined $url->host and ($url->host eq 'facebook.com' or $url->host eq 'www.facebook.com');
        next if length $url->path and $url->path ne '/';
        print "$inputn";
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 23 '18 at 20:08









        Grinnz

        1,902311




        1,902311






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53441280%2fhow-to-ignore-all-after-domain-zone-except-symbol%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Basket-ball féminin

            Different font size/position of beamer's navigation symbols template's content depending on regular/plain...

            I want to find a topological embedding $f : X rightarrow Y$ and $g: Y rightarrow X$, yet $X$ is not...