Jquery extract url from text

I need to extract url from text using jquery.

Lets say that I have sowhere on the page following the textarea code

<textarea rows="20" name="textarea" style="width:100%;"> @techreport{blabl, blabla = {}, url = {http://server.com/thepdf.pdf}, wrongurl ={http://server.com/thepdf2.pdf}, blablabla = 1998, blablablabla= {blablablablabla}} </textarea> 

I need url and only url content is not misurl.

Update: it always has the same structure, and I only need to extract it ONCE, and it always has "url = {" in front of it.

0
jquery url extract
source share
4 answers

how about this

 $(document).ready(function() { $('#click').click(function(){ var one = document.getElementById('one'); one.value.match(/url ={([^}]*)}/,""); alert( RegExp.$1); }) }) 

or demo version http://jsfiddle.net/PePS7/10/

Oops, a little late to the game, but an example introduced in the example, and jsfiddle - show only the URL

+2
source share

You will need to do some Reg ex on this. If I were better, I would write for you.

0
source share

jQuery will not do this, you are looking for a regular expression to extract the url from the url property in this text box. You can do this with the following regex:

/url = \{(.+)\}/.exec(textarea_str)[1]

0
source share

The easiest thing to do is use a regex, as everyone pointed out.

 /url = \{([^}]*)\}/ 

This regex should do it.

0
source share

Source: https://habr.com/ru/post/650366/


All Articles