'Regex get text between first p tags
I'm trying to edit the Original code to get the first p tag from product.description and tried the New Code, but with no success. Is there another method anyone can recommend? Thanks in advance for your help.
Original Code:
if (quickview.find('.des').length > 0) {
var description = product.description.replace(/(<([^>]+)>)/ig, "");
quickview.find('.des').text(description);
}
New Code:
if (quickview.find('.des').length > 0) {
var description = product.description.match(/<p>(.*?)<\/p>/g, "");
quickview.find('.des').text(description);
}
Example parse for New Code:
<p>First inner content needed.</p> <p>content...</p> <span>content...</span>
I'm trying to grab everything inside the first paragraph only and need to remove all p tags and any other tags after.
Solution 1:[1]
if (quickview.find('.des').length > 0) {
var description = product.description.match(/<p class="desQuickView">(.*?)<\/p>/g, "").map(function(val){
return val.replace(/(<([^>]+)>)/ig, "");
});
quickview.find('.des').text(description);
I found a way to target my first paragraph by adding a class name. Then I look for all tags and replaced them with an empty strings.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | user1917032 |
