podeig
podeig

Reputation: 2741

How to get the first sentence from the first paragraph?

How to get the first sentence from the first paragraph?

 <h2>Test</h2>
 <p class="preserve">
      Morbi in sem quis dui placerat ornare. Pellentesque odio nisi. Euismod in pharetra a, diam.
 </p>
 <p class="preserve">
      Morbi in sem quis dui placerat ornare. Pellentesque odio nisi. Euismod in pharetra a, diam.
 </p>

My regex take all the sentences from the first and the second paragraph.

<p.*>.*\.\s[A-Z]

Upvotes: 0

Views: 1004

Answers (3)

Brian Dishaw
Brian Dishaw

Reputation: 5825

This will put the first sentence of each paragraph in Group 1

<p.*>\s*([A-Z].+?)(?=\.\s[A-Z])

Upvotes: 1

Sly
Sly

Reputation: 361

/<p[^>]*>(.|\s)*([A-Z][^<.]*)\./gU

demo

Upvotes: 1

Sergii Lagutin
Sergii Lagutin

Reputation: 10681

Steps:

  • setup single line mode
  • skip first p tag and space charactes after it - <p.*?>\s+
  • grab all before first dot .*?\..

regex demo

<p.*?>\s+(.*?)\.

Upvotes: 2

Related Questions