English 中文(简体)
A. 从段落到联合材料系列的单独网络链接
原标题:Separate web links from paragraph into a JS array

我检查了上述所有答复,看看是否回答了地雷问题,请不要说这重复了。

在一栋楼房的申请中,有一栋小块。

<div class="paragraphlink"> </div>

我允许用户加入这样的案文。

Räikkönen was among the two Formula One drivers http://www.formula1.com who made it into the Forbes magazine s The Celebrity 100 list, the other being Fernando Alonso http://www.google.com. He is 36th on Forbes magazine s http://www.forbesmagazine.com

如果你注意到,上述段落有斜体。 您能帮助我制定一部 j法,从上述段落中提取所有ur?

最佳回答

页: 1

var reg = new RegExp(/http(s)?://[a-z0-9_-./]+/ig);

var html = "Räikkönen was among the two Formula One drivers http://www.formula1.com who made it into the Forbes magazine s The Celebrity 100 list, the other being Fernando Alonso http://www.google.com. He is 36th on Forbes magazine s http://www.forbesmagazine.com"

html.match(reg);

will return you an array of urls.

问题回答

您可使用您文本中的对应功能,以摘录,例如:

var str = "Räikkönen was among the two Formula One drivers http://www.formula1.com who made it into the Forbes magazine s The Celebrity 100 list, the other being Fernando Alonso http://www.google.com. He is 36th on Forbes magazine s http://www.forbesmagazine.com";

var urls = str.match(/http(s)?://[a-z0-9_-./]+/ig);
// now the var "urls" is in array with your URL

但在这方面,你可以发现许多网站的情况更好。

定期使用

定期表达

     /(http|https|ftp|ftps)://[a-zA-Z0-9-.]+.[a-zA-Z]{2,3}(/S*)?/g

卢旺达

http://www.w3schools.com/jsref/jsref_obj_regexp.asp”rel=“nofollow”>this和rel=“nofollow”>this





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签