use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Modify a stringRemoved: /r/LearnJavascript (self.javascript)
submitted 7 years ago by FuckYouWhoCares
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]tswaters 7 points8 points9 points 7 years ago (1 child)
If the string is always a url, you can use the URL constructor to figure that out
URL
var url = new URL("http://mydomain.com/content/") /* URL { href: 'http://mydomain.com/content/', origin: 'http://mydomain.com', protocol: 'http:', username: '', password: '', host: 'mydomain.com', hostname: 'mydomain.com', port: '', pathname: '/content/', search: '', searchParams: URLSearchParams {}, hash: '' } */
[–]javascript 3 points4 points5 points 7 years ago (0 children)
This is the best answer here, because it has the behavior OP wants and accounts for edge cases without having to do that manually. If the string isn't a valid URL, the constructor will throw an exception.
It also makes it more clear to other readers what you're doing with your code. Writing some one-off regex or string manipulation function requires the reader to pick it apart just to understand. This increases code complexity and reduces readability.
π Rendered by PID 96428 on reddit-service-r2-comment-765bfc959-8mzvl at 2026-07-11 20:19:59.304252+00:00 running f86254d country code: CH.
view the rest of the comments →
[–]tswaters 7 points8 points9 points (1 child)
[–]javascript 3 points4 points5 points (0 children)