JS regex. Matching URL

M

Merlin

Hello,

I am trying to find out how to create a line of JS code to do a regex to match a
URL inside a text. I don't want to know if it is valid, but just if there is a
URL inside a text.
Can anybody give me quick start on how I can acchive this? I surfed a couple of
regex sites, but could not find a solution so far.

Thank you in advance.

Merlin

PS: Is it also possible with regex to find out if the text contains just out of
High case letters? For example HELLO instead of Hello
 
M

Michael Winter

I am trying to find out how to create a line of JS code to do a regex to
match a URL inside a text. I don't want to know if it is valid, but just
if there is a URL inside a text.

It depends on the form that the URL might take (and what you want to
allow). A regular expression that accepts a full RFC 3986-compliant URL
will be very long (though not particularly complex), whereas you might
want something more restrictive. Also, will the URLs only be absolute
(including scheme), just the authority and path, or either?

[snip]
PS: Is it also possible with regex to find out if the text contains just
out of High case letters? For example HELLO instead of Hello

The easiest approach is to search for any lower-case letters.

if(!/[a-z]/.test( string )) {
/* Does not contain lower-case letters */
}

This would not check for numbers, whitespace, or punctuation.

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top