By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,842 Members | 2,440 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,842 IT Pros & Developers. It's quick & easy.

JS regex. Matching URL

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a

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.