Link to home
Start Free TrialLog in
Avatar of Jim Schwetz
Jim Schwetz

asked on

Find and replace part of inner div

How do I find and replace to remove inside div child element, keeping everything (all <p>*</p>'s) .  some times their is just on p element, and sometimes alot.
link to regex101
<div class="expand_collapse section_box">
     <h2>Animal </h2>
     <div class="box_content">                        
          <div class="expand_collapse section_box">
              <h2>Agent Facing</h2>
               <div class="box_content">
                  <p><a href="/Brochure.pdf" target="_blank">Animal<br>(bully breeds &amp; bite history)</a></p>                                                   
              </div>
          </div>
          <div class="expand_collapse  section_box">
              <h2>Consumer Facing</h2>
              <div class="box_content">
                 <p>content</p>
              </div>
          </div>
       </div>
   </div>
   <!-- Next Product -->

Open in new window


I just want to remove:
 <div class="expand_collapse section_box">
      <h2>Agent Facing</h2>
       <div class="box_content">

Open in new window

and
                           </div>
                        </div>
                        <div class="expand_collapse  section_box">
                          <h2>Consumer Facing</h2>
                          <div class="box_content">
                            <p>content</p>
                          </div>
                        </div>

Open in new window

so keeping one or more of the 'P' elements inside the second div.box_content element.
I think I need to create a group for one or many p elements  (<p>.*</p>)  then replace with $1? So I keep the p's? (This does not work)
Can you provide a link to a resource to help me with regex as I do a lot of replaces/removals.

It would look like this when done.
<div class="expand_collapse section_box">
    <h2>Animal </h2>
     <div class="box_content">                        
         <p><a href="/Brochure.pdf" target="_blank">Animal<br>(bully breeds &amp; bite history)</a></p>
      </div>
</div>
<!-- Next Product -->

Open in new window


Thanks in advance.   I am not good with regex.
Avatar of Jim Schwetz
Jim Schwetz

ASKER

I got it to work with (.*?) to capture the group,  but it only worked if only one <p>,  it did not find the sets with multiple <p> lines.
ASKER CERTIFIED SOLUTION
Avatar of rpremuz
rpremuz
Flag of Croatia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for the help rpremuz, This is a skill I need to get better at.  

Thanks,
Jim