简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM