开发者

get meta element property with Javascript Regex

开发者 https://www.devze.com 2023-03-13 08:59 出处:网络
How would i construct a Javascript regex to get the content attribute from the following meta element?

How would i construct a Javascript regex to get the content attribute from the following meta element?

<meta c开发者_开发技巧ontent="59.949444" property="og:latitude">

This is what my code looks like so far:

var url = 'test.html';

$.get(url, function(data){

  var pattern = /property="og:latitude"\scontent=".+?"/;   
  var matches = data.match(pattern);

  console.info(matches[0]);

});


Swap the order of the items:

/content=\"(.+)\"\s+property=\"og:latitude\"/


Try this:

//...
     var pattern = /property="og:latitude"\scontent="(.+?)"/;   
      var matches = data.match(pattern);
      console.info(matches[1]);
0

精彩评论

暂无评论...
验证码 换一张
取 消