I am trying to make a regex that checks if the url a user is posting, are valid.
I have created the following regex:
/https?\:\/steamcommunity\/.com\/profiles|id\/[a-zA-Z0-9]/
But that isn't working. Is there a regex master, here that can tell me what i am doing wrong?
The links i am trying to validate are looking like:
https://steamcommunity.com/profiles/76561198009610232/
https://steamcommunity.com/id/rasmusvejby/
ANSWERE
/(?:https?:\/\/)?steamcommunity\.com\/(?:profiles|id)\/[a-zA-Z0-9]+/
Try this regex:
(?:https?:\/\/)?steamcommunity\.com\/(?:profiles|id)\/[a-zA-Z0-9]+
See this demo:
Regex Demo
The "g" modifier is just so you can see it test it in different strings, but you probably dont need it.
The accepted answer to this question will also match this url for example:
https://steamcommunity.com/profile/thisisimpossible
I am using the following regex to prevent non numeric characters when the id is prepended by profile/ rather than id/. Not necessarily prettier but it does the job.
^(?:https?:\/\/)?steamcommunity\.com\/(?:profiles\/[0-9]{17}|id\/[a-zA-Z0-9].*)$
Related
I am using the following regex for validating youtube video share url's.
var valid = /^(http\:\/\/)?(youtube\.com|youtu\.be)+$/;
alert(valid.test(url));
return false;
I want the regex to support the following URL formats:
http://youtu.be/cCnrX1w5luM
http://youtube/cCnrX1w5luM
www.youtube.com/cCnrX1w5luM
youtube/cCnrX1w5luM
youtu.be/cCnrX1w5luM
I tried different regex but I am not getting a suitable one for share links. Can anyone help me to solve this.
Here's a regex I use to match and capture the important bits of YouTube URLs with video codes:
^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube(-nocookie)?\.com|youtu.be))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$
Works with the following URLs:
https://www.youtube.com/watch?v=DFYRQ_zQ-gk&feature=featured
https://www.youtube.com/watch?v=DFYRQ_zQ-gk
http://www.youtube.com/watch?v=DFYRQ_zQ-gk
//www.youtube.com/watch?v=DFYRQ_zQ-gk
www.youtube.com/watch?v=DFYRQ_zQ-gk
https://youtube.com/watch?v=DFYRQ_zQ-gk
http://youtube.com/watch?v=DFYRQ_zQ-gk
//youtube.com/watch?v=DFYRQ_zQ-gk
youtube.com/watch?v=DFYRQ_zQ-gk
https://m.youtube.com/watch?v=DFYRQ_zQ-gk
http://m.youtube.com/watch?v=DFYRQ_zQ-gk
//m.youtube.com/watch?v=DFYRQ_zQ-gk
m.youtube.com/watch?v=DFYRQ_zQ-gk
https://www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US
http://www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US
//www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US
www.youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US
youtube.com/v/DFYRQ_zQ-gk?fs=1&hl=en_US
https://www.youtube.com/embed/DFYRQ_zQ-gk?autoplay=1
https://www.youtube.com/embed/DFYRQ_zQ-gk
http://www.youtube.com/embed/DFYRQ_zQ-gk
//www.youtube.com/embed/DFYRQ_zQ-gk
www.youtube.com/embed/DFYRQ_zQ-gk
https://youtube.com/embed/DFYRQ_zQ-gk
http://youtube.com/embed/DFYRQ_zQ-gk
//youtube.com/embed/DFYRQ_zQ-gk
youtube.com/embed/DFYRQ_zQ-gk
https://www.youtube-nocookie.com/embed/DFYRQ_zQ-gk?autoplay=1
https://www.youtube-nocookie.com/embed/DFYRQ_zQ-gk
http://www.youtube-nocookie.com/embed/DFYRQ_zQ-gk
//www.youtube-nocookie.com/embed/DFYRQ_zQ-gk
www.youtube-nocookie.com/embed/DFYRQ_zQ-gk
https://youtube-nocookie.com/embed/DFYRQ_zQ-gk
http://youtube-nocookie.com/embed/DFYRQ_zQ-gk
//youtube-nocookie.com/embed/DFYRQ_zQ-gk
youtube-nocookie.com/embed/DFYRQ_zQ-gk
https://youtu.be/DFYRQ_zQ-gk?t=120
https://youtu.be/DFYRQ_zQ-gk
http://youtu.be/DFYRQ_zQ-gk
//youtu.be/DFYRQ_zQ-gk
youtu.be/DFYRQ_zQ-gk
https://www.youtube.com/HamdiKickProduction?v=DFYRQ_zQ-gk
The captured groups are:
protocol
subdomain
domain
path
video code
query string
https://regex101.com/r/vHEc61/1
You're missing www in your regex
The second \. should optional if you want to match both youtu.be and youtube (but I didn't change this since just youtube isn't actually a valid domain - see note below)
+ in your regex allows for one or more of (youtube\.com|youtu\.be), not one or more wild-cards.
You need to use a . to indicate a wild-card, and + to indicate you want one or more of them.
Try:
^(https?\:\/\/)?(www\.youtube\.com|youtu\.be)\/.+$
Live demo.
If you want it to match URLs with or without the www., just make it optional:
^(https?\:\/\/)?((www\.)?youtube\.com|youtu\.be)\/.+$
Live demo.
Invalid alternatives:
If you want www.youtu.be/... to also match (at the time of writing, this doesn't appear to be a valid URL format), put the optional www. outside the brackets:
^(https?\:\/\/)?(www\.)?(youtube\.com|youtu\.be)\/.+$
youtube/cCnrX1w5luM (with or without http://) isn't a valid URL, but the question explicitly mentions that the regex should support that. To include this, replace youtu\.be with youtu\.?be in any regex above. Live demo.
I know I'm like 2 years late to the party, but I was needing to write something up anyway, and seems to fit every test case that I can throw at it. Should be able to reference the first match ($1) to get the ID. Matches the http, https, www and non-www, youtube.com, youtu.be, /watch? and /watch.php? on youtube.com (youtu.be does not use these), and it supports matching even when there are other variables in the URL string (?t= for time, ?list= for playlists, etc).
(?:https?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]+)
Format for YouTube videos has changed. This regex works for all cases:
^(http(s)??\:\/\/)?(www\.)?((youtube\.com\/watch\?v=)|(youtu.be\/))([a-zA-Z0-9\-_])+
Tests here.
Based on so many other regex; this is the best I have got:
((http(s)?:\/\/)?)(www\.)?((youtube\.com\/)|(youtu.be\/))[\S]+
Test:
http://regexr.com/3bga2
Try this:
((http://)?)(www\.)?((youtube\.com/)|(youtu\.be)|(youtube)).+
http://regexr.com?36o7a
I took one of the answers from here and added support for a few edge cases that I noticed in my dataset. This should work for pretty much any valid url.
^(?:https?:)?(?:\/\/)?(?:youtu\.be\/|(?:www\.|m\.)?youtube\.com\/(?:watch|v|embed)(?:\.php)?(?:\?.*v=|\/))([a-zA-Z0-9\_-]{7,15})(?:[\?&][a-zA-Z0-9\_-]+=[a-zA-Z0-9\_-]+)*(?:[&\/\#].*)?$
I tried this one and it works fine for me.
(?:http(?:s)?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/))([^\?&\"'<> #]+)
You can check here https://regex101.com/r/Kvk0nB/1
https://regexr.com/62kgd
^((http|https)\:\/\/)?(www\.youtube\.com|youtu\.?be)\/((watch\?v=)?([a-zA-Z0-9]{11}))(&.*)*$
https://www.youtube.com/watch?v=YPz9zqakRbk
https://www.youtube.com/watch?v=YPz9zqakRbk&t=11
http://youtu.be/cCnrX1w5luM&y=12
http://youtu.be/cCnrX1w5luM
http://youtube/cCnrXswsluM
www.youtube.com/cCnrX1w5luM
youtube/cCnrX1w5luM
Check this pattern instead:
r'(?i)(http.//|https.//)*[A-Za-z0-9._%+-]+\.\w+'
I have this input string for a regular expression
ine",monitor_crashes:false,container_type:null,min_aspect_ratio:0.25,max_aspect_ratio:4,number_of_partitions:2,multi_partitioning_enabled:false,access_token:"EAAAAUaZA8jlABAOZC1TJwwFgfHyWt4V6b6B6cNxMXKkrjcpmzYS2vB7GWnIJFZCFQMPPEoZCInyJVigwcn8DtZA9xtYNATZBZBriOZBjAhdZCMfZCwohKOISSpC8aewclxA3U3X2PqPZBwZCdZBcKNA2Ydr2pQECR6ZBbuOaAZD",resumability_enabled:true,resumable_service_override:null,change_default_chunk_size:true,client_chunk_size:200000000,use_real_progress_percentage:false,use_progress_linearity:0,use_progress_transform_x:1,early_receive:false
I try to grab access token. But result return not single value.
I want single value:
"EAAAAUaZA8jlABAOZC1TJwwFgfHyWt4V6b6B6cNxMXKkrjcpmzYS2vB7GWnIJFZCFQMPPEoZCInyJVigwcn8DtZA9xtYNATZBZBriOZBjAhdZCMfZCwohKOISSpC8aewclxA3U3X2PqPZBwZCdZBcKNA2Ydr2pQECR6ZBbuOaAZD"
How to improvement my regex.
My test https://www.debuggex.com/r/xPqpBV3e9h2yoghE
My regex: (\w)+(?="|access_token$)
Your current regex, (\w)+(?="|access_token$), matches any length (>= 1) of word characters followed either by an " or by access_token$. I'm really not sure why you would want to have it followed by access_token$, because the access_token comes before the text you're looking for.
I don't know why a simple regex like: access_token:"(\w+)\" wouldn't work? (the first capturing group is the string) It looks for the string with the key access_token.
Then again, as #desoares said in the comments, it's probably best to parse this JSON with a JSON parser, using: JSON.parse(yourJsonObjectString).access_token.
This regular expression is what would work:
RegEx: access_token:"(\w+?)"
Click Here to see Screen Capture of Solution using your page "Debuggex.com"
Regex = ([A-Z]\w+)
Reference:
enter link description here
I have been using the following regex, to check if it is a valid facebook url: /^(?:(?:http|https):\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-]*)?$/
The problem is that, this regex is old, and now some facebook url's has a . and ?fref=ufi in there url example: https://www.facebook.com/user.moreusername?fref=ufiHow can i fix so that this regex accept that kind of url?
I have been trying to add \/?(?:?fref=ufi.)?\/ Without any luck.
Only going off of what you have provided, I have found this to work:
^(?:(?:http|https):\/\/)?(?:www.)?facebook.com\/(?:(?:\w)*#!\/)?(?:pages\/)?(?:[?\w\-]*\/)?(?:profile.php\?id=(?=\d.*))?([\w\-\.]*)?(?:\?fref=ufi)?$
The difference is in:
([\w\-\.]*)? // added the \. for matching the . literally
(?:\?fref=ufi)?$ // this was appended to the end
Regex101
This may not work for all scenarios as I only have your test case to work off of.
I am working something to exclude some URL.
I want to expect all URLs with the pattern /google.com/, except for /login.google.com/
So:
account.google.com should pass
google.com should pass
google.com/abc should pass
http://google.com should pass
login.google.com should not pass
The code I am trying is
/^(?!login\.)google\.com/
/^(login)google\.com/
but neither is working. Am I missing something?
Assuming you're trying to match any google.com address except ones that begin with login., you need to just add a .* prior to the google, i.e.
/^(https?:\/\/)?(?!login\.)([\w-]+\.)?google\.com/
Update: Modified based on helpful comments. Not sure what the valid domain name character class is - took a guess at that as being [\w-]. See http://rubular.com/ if you want to play with it.
This regex should work for you:
^(?:https?://)?(?!login\.)(?:.+?\.)?google\.com(?:/.*|)$
Live Demo: http://www.rubular.com/r/z69WSKV9cM
Javascript syntax:
/^(?:https?:\/\/)?(?!login\.)(?:.+?\.)?google\.com(?:\/.*|)$/
Try this pattern to match the data listed in the question:
/^(account\.)?google\.com/
I'm trying to write a regexp which allow me to filter out all the url addresses having this shape.
http://foo.com/
http://foo
http://foo.*
But not the following:
http://foo.com/subfoo
http://foo.com/subfoo/
http://foo.com/subfoo/subsubfoo..
In order to match the second url group i've written the following regexp:
http://.*/.
However my problem is search the regexp matching the first group.
So i need a way to say:
if after http://.* or http.//.*/ there is nothing, matches the pattern.
I've read something on lookhaead. I don't know it this might be the right way.
Any idea? Thanks for your answer.
A bit late, but this worked for me:
http://[^/]*[/]*$
/^http:\/\/[^/?#]*\/./i
should match only http URLs with a path component other than /.
Don't forget query strings like this: http://foo.com/?search
/^http:\/\/[^/?#]*\/[^?]/i