-1

HTML:

<textarea name="test">
  http://google.com/
  https://google.com/
  http://www.google.com
  www.google.com/
  [url=http://google.com/]test[/url]
  text
</textarea>

jQuery:

$('button').click(function() {
    if ($('textarea[name="test"]').val().match(/\[url/)) {
        alert('links exist');
    }
});

What kind of regular expressions will match every URL instance I have in my <textarea>?

jsFiddle: http://jsfiddle.net/5Z8AU/

O P
  • 2,327
  • 10
  • 40
  • 73
  • 2
    Why did you give no feedback to the answers on your previous, very similar [post](http://stackoverflow.com/questions/15044680/detect-and-remove-urls-from-textarea/15044846#comment21158867_15044846)? – MikeM Feb 24 '13 at 15:26

1 Answers1

0

There are more detailed answers here. But if you are looking for a simple Regex that handles only the cases you listed this will do.

(http|\[url|www)[^\s]*(/|com|url])

It can be understood as this part being the start of the string

(http|\[url|www) anything that starts with http, [url, or www

Accepting any matching characters that are not a space

[^\s]*

And this being the end of she string

(/|com|url]) anything that ends with /, com, or url]
Community
  • 1
  • 1