kulfi kulfi - 1 month ago 5
HTML Question

Get text wrapped into <b> and separated by <br> using jquery

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?

Answer

Use this regex

var Date= str.match(/(\d{4})-(\d{2})-(\d{2})-(\d{2})-(\d{2})-(\d{2})/g);