-1

Regex expression is working when the content is in the same line. But it does not work if the same content is in multiple line. Please identify a mistake

Regex:

   <([^\s]+).*?id="opensource".*?>(.+?)<\/\1>

It works with content in same line:

  <article id="opensource">Cabby </article>

It does not works with content in different line:

 <article id="opensource">
  Cabby
 </article>
learner
  • 23
  • 1
  • 6

1 Answers1

0

You need to account for the whitespace characters.

<([^\s]+).*?id="opensource".*?>(?:\s+)?(.+?)(?:\s+)?<\/\1>

Here is a working example: https://regex101.com/r/OQH7A5/1

10100111001
  • 1,832
  • 1
  • 11
  • 7