How to ignore all after domain zone except symbol “/”
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
regex string perl pcre
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
|
show 1 more comment
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
|
show 1 more comment
2 Answers
2
active
oldest
votes
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 protocolhttps?://
, zero or one time?
(optional)
(?:www.)?
non-capturing group that will match onwww.
, 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.
Thanks @K.Dᴀᴠɪs. This regex work for me.
– Andreas Hunter
Nov 23 '18 at 6:06
add a comment |
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";
}
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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 protocolhttps?://
, zero or one time?
(optional)
(?:www.)?
non-capturing group that will match onwww.
, 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.
Thanks @K.Dᴀᴠɪs. This regex work for me.
– Andreas Hunter
Nov 23 '18 at 6:06
add a comment |
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 protocolhttps?://
, zero or one time?
(optional)
(?:www.)?
non-capturing group that will match onwww.
, 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.
Thanks @K.Dᴀᴠɪs. This regex work for me.
– Andreas Hunter
Nov 23 '18 at 6:06
add a comment |
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 protocolhttps?://
, zero or one time?
(optional)
(?:www.)?
non-capturing group that will match onwww.
, 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.
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 protocolhttps?://
, zero or one time?
(optional)
(?:www.)?
non-capturing group that will match onwww.
, 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.
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
add a comment |
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
add a comment |
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";
}
add a comment |
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";
}
add a comment |
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";
}
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";
}
answered Nov 23 '18 at 20:08
Grinnz
1,902311
1,902311
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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