Javascript正则表达式问题
str = 'autocomplete=\\\"off\\\" name=\\\"composer_session_id\\\" value=\\\"1557423901\\\" \\\/>\\u003cinput type=\\\"hidden\\\" autocomplete=\\\"off\\\" name=\\\"is_explicit_place\\\" id=\\\"u436754_5\\\"';
或者使用这个字符串,
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\",
我希望 str.match()
返回 composer_session_id
的值,即“1557423901”,也是 的
即“u436754_5”。id
is_explicit_plac
如何使用 JavaScript regex.match() 或 split or else
获取“1557423901”和“u436754_5”?
注意:在每种情况下,都保证 name
位于 value
之前。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 JavaScript 没有lookbehinds,我编写了这个与
'attribute=\\\"value\\\"'
匹配的代码片段,然后删除'attribute=\\\"
> 和\\\"
部分。享受!
Since JavaScript doesn't have lookbehinds, I wrote this snippet that matches
'attribute=\\\"value\\\"'
then removes the'attribute=\\\"
and\\\"
parts.Enjoy!