Parse string in javascript

22,914

Solution 1

try this : 

  var g=string.match(/set=[a-z]\.([^.]+)/);

g[1] will have the value

http://jsbin.com/anuhog/edit#source

Solution 2

You could use split() to modify your code like this:

var newstring = string.match(/set=[^ ]+/)[0].split(".")[1]; 

For a more generic approach to parsing query strings see:

Parse query string in JavaScript

Using the example illustrated there, you would do the following:

var newstring = getQueryVariable("set").split(".")[1];

Share:
22,914
Robin Carlo Catacutan
Author by

Robin Carlo Catacutan

Likes: Lots of Coffee Mostly involve in: Javascript, Html, CSS, PHP, Python What I do now: Learning the beauty of Functional Programming(Clojure)

Updated on January 26, 2022

Comments

  • Robin Carlo Catacutan
    Robin Carlo Catacutan over 2 years

    How can I parse this string on a javascript,

    var string = "http://www.facebook.com/photo.php?fbid=322916384419110&set=a.265956512115091.68575.100001022542275&type=1";

    I just want to get the "265956512115091" on the string. I somehow parse this string but, still not enough to get what I wanted.

    my code:

    var newstring = string.match(/set=[^ ]+/)[0]; 
    

    returns:

    a.265956512115091.68575.100001022542275&type=1