将文本包装到中,并使用jquery通过进行分隔(Get text wrapped into and separated by using jquery)
我以html字符串格式从服务接收输出,如下所示:
"<html>↵<h1>↵Example : ↵<br>Explanation↵</h1>↵<hr>↵<b>key1 : ABCD <br>key2 : 2016-10-18-18-38-29<br>Output: /acddfd/example</b>↵</html>↵"然后我解析html来获取标签<b> ,如下所示:
var input="<html>↵<head>↵<h1>↵Example : ↵<br>Explanation↵</h1>↵<hr>↵<b>key1 : ABCD <br>key2 : 2016-10-18-18-38-29<br>Output: /acddfd/example</b>↵</html>↵"; var parsed= $.parseHTML(input);然后我发现解析为一个html标签数组:
<b>key1 : ABCD <br>Date : 2016-10-18-18-38-29<br>Output: /acddfd/example</b>现在我需要获取Date的值以进一步操作。 任何人都可以帮助我使用js / jquery获取Date (例如2016-10-18-18-38-29 )的值吗?
I receive the output from services in html string format as follow :
"<html>↵<h1>↵Example : ↵<br>Explanation↵</h1>↵<hr>↵<b>key1 : ABCD <br>key2 : 2016-10-18-18-38-29<br>Output: /acddfd/example</b>↵</html>↵"Then I parse the html to get tag <b> as follows:
var input="<html>↵<head>↵<h1>↵Example : ↵<br>Explanation↵</h1>↵<hr>↵<b>key1 : ABCD <br>key2 : 2016-10-18-18-38-29<br>Output: /acddfd/example</b>↵</html>↵"; var parsed= $.parseHTML(input);Then I find parsed as an array of html tags:
<b>key1 : ABCD <br>Date : 2016-10-18-18-38-29<br>Output: /acddfd/example</b>Now I need to get the value of Date for further operation. Can anyone help me to get the value of Date (e.g.2016-10-18-18-38-29) using js/jquery?
最满意答案
使用这个正则表达式
var Date= str.match(/(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})/g);Use this regex
var Date= str.match(/(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})/g);更多推荐
发布评论