0
str = 'autocomplete=\\\"off\\\" name=\\\"composer_session_id\\\" value=\\\"1557423901\\\" \\\/>\\u003cinput type=\\\"hidden\\\" autocomplete=\\\"off\\\" name=\\\"is_explicit_place\\\" id=\\\"u436754_5\\\"';

or use this string

session_id\":1557423901,\"include_source\":\"web_composer\",\"allow_cities\":true},\"bootstrapEndpoint\":\"\\\/ajax\\\/places\\\/typeahead.php\"});},\"j4e8191ff7ff1878042874292\":function(){return new Typeahead(JSCC.get('j4e8191ff7ff1878042874291'), {node_id: \"u436754_1\",

i want that str.match() return value of composer_session_id which is "1557423901" and also the id of is_explicit_plac which is "u436754_5".

How to get "1557423901" and "u436754_5" using JavaScript regex.match() or split or else?

Note: It's guaranteed that name will precede value in each case.

4
  • 1
    Why do you need match for this? Seems split is better suited here, merely split on id= and value=. Commented Sep 27, 2011 at 9:49
  • will be easier to from this string Commented Sep 27, 2011 at 9:49
  • session_id\":1557423901,\"include_source\":\"web_composer\",\"allow_cities\":true},\"bootstrapEndpoint\":\"\\\/ajax\\\/places\\\/typeahead.php\"});},\"j4e8191ff7ff1878042874292\":function(){return new Typeahead(JSCC.get('j4e8191ff7ff1878042874291'), {node_id: \"u436754_1\" Commented Sep 27, 2011 at 9:49
  • i need session_id and node_id values which are 1557423901 and u436754_1 respectivly. use any function , i just want these value Commented Sep 27, 2011 at 9:50

1 Answer 1

1

Since JavaScript doesn't have lookbehinds, I wrote this snippet that matches 'attribute=\\\"value\\\"' then removes the 'attribute=\\\" and \\\" parts.

var matches = str.match(/(?:name|id|value)=\\".*?\\"/g);
for (var key in matches)
    matches[key]=matches[key].replace(/.*?\\"(.*?)\\"/,"$1");

Enjoy!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.