# Help with regex and \<p\> tag

**URL:** <https://www.ruby-forum.com/t/help-with-regex-and-p-tag/239481>\
**Category:** Rails\
**Created:** [February 28, 2014, 3:03pm UTC](https://www.ruby-forum.com/t/help-with-regex-and-p-tag/239481 "2014-02-28T15:03:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [February 28, 2014, 3:03pm UTC](https://www.ruby-forum.com/t/help-with-regex-and-p-tag/239481/1 "2014-02-28T15:03:28Z")

</div>

Hi,

I need to create a regex to extract 4 paragraphs of a text:

**Topic** – abc

abcd

abcde

abcdef

abcdefg

I need to extract 4 paragraphs (text inside

 including some html  
code) of this text using a regex.

How can I solve this problem ? I’ve tried a lot but I cant do this.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![guilhermemm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@guilhermemm](https://www.ruby-forum.com/u/guilhermemm)\
**Post date:** [February 28, 2014, 3:11pm UTC](https://www.ruby-forum.com/t/help-with-regex-and-p-tag/239481/2 "2014-02-28T15:11:42Z")

</div>

On Friday, February 28, 2014 1:31:30 PM UTC, Guilherme wrote:

> 

The standard advice would be to not use regular expressions - use an  
html  
parser like nokogiri.

Fred

---

<div class="post-metadata">

**Author:** ![guilhermemm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/ed8c4c/32.png) [@guilhermemm](https://www.ruby-forum.com/u/guilhermemm)\
**Post date:** [February 28, 2014, 7:28pm UTC](https://www.ruby-forum.com/t/help-with-regex-and-p-tag/239481/3 "2014-02-28T19:28:53Z")

</div>

Yes sir.  
Thanks for the tip.  
This code makes the magic:

```
  doc = Nokogiri::HTML("<p>test</p>")
  doc.search("p")
```
