Reputation: 8889
I have the following script, where I parse entire HTML and bind to a div (Homepage):
function htmlResponse() {
var res = "";
debugger;
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
options.async = true;
});
$.ajax({
url: "http://localhost:1469/Home.aspx",
success: function (result) {
res = result;
res = res.replace(/\/CMSPages\/GetResource\.ashx/g, 'http://localhost:1469/CMSPages/GetResource.ashx');
res = res.replace(/\/WebResource\.axd/g, 'http://localhost:1469/WebResource.axd');
res = res.replace('<ul>', '<ul class="fallback browse-experience-drop-down-width">');
$("#homePage").html(res);
}
}).done(function () {
});
};
res
variable contains full HTML which needs to be binds to div homepage.
How I can write another regex which will fetch only <HEADER>
till </HEADER>
and <FOOTER>
till </FOOTER>
?
And bind those two sections in two div tags?
Something like below:
header = res.regex("REGEX FOR FETCHING HEADER");
footer = res.regex("REGEX FOR FETCHING FOOTER");
$("#HEADER").html(header);
$("#FOOTER").html(footer);
Upvotes: 0
Views: 500
Reputation: 1688
You can try this.
For header:
/<(?:HEADER|header)>([\s\S]*?)<\/(?:HEADER|header)>/g
For footer:
/<(?:footer|FOOTER)>([\s\S]*?)<\/(?:footer|FOOTER)>/g
Upvotes: 1