将文本包装到中,并使用jquery通过进行分隔(Get text wrapped into and separated by using jquery)

编程入门 行业动态 更新时间:2024-10-24 23:23:44
文本包装到中,并使用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);

更多推荐

本文发布于:2023-07-04 11:09:00,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本   jquery   text   wrapped   separated

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!