469,580 Members | 1,895 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,580 developers. It's quick & easy.

JS regex. Matching URL

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
Oct 3 '05 #1
2 2161
On 03/10/2005 11:13, Merlin wrote:
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

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 3 '05 #2

To check for an url in a string, is quite simple, as for cases and such, js
follows pretty much Perl regexps, so it's regexps are Perlish and they can
discriminate the pattern very keenly and quite close to exactly what you
want, so, you need to be more specific or such.
Danny
Oct 4 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by aeuglein | last post: by
2 posts views Thread by mikea59 | last post: by
3 posts views Thread by Day Of The Eagle | last post: by
7 posts views Thread by bill tie | last post: by
5 posts views Thread by Kofi | last post: by
7 posts views Thread by CB | last post: by
reply views Thread by Tidane | last post: by
4 posts views Thread by pedrito | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.