Match groups between tags over multiple lines via regex

167 Views Asked by At

I want to match groups between opening and ending tags in a multiline text via regular expression.

I know that this question has been asked a lot before here in this community... Unfortunately, I am facing some restrictions of my regex parser in this way that I cannot use whole language support of regular expression. For example, it is not possible to use shortcuts like \s or \S :(...

Example source:

<html>
  <p>
   Line 1
   Line 2
   Line 3
  </p>
</html>

The following regex would work perfectly: (<p>[\s|\S]+</p>).

As I mentioned before, I am not able to use shortcuts like \s or \S. Therefore I tried to rewrite the regex by using character classes like [:space:].

And that's the point I don't understand what's happening. If I simply replace the \s and \S by [[:space:]] and [^[:space:]] the regex does not work anymore... (<p>[[^[:space:]]|[[:space:]]]+</p>)

Can anyone help me out here?

BR Steve

1

There are 1 best solutions below

0
sln On

You might have some extra brackets there.

This seems to work.

<p>(([^[:space:]]|[[:space:]])+?)</p>

https://regex101.com/r/D9pydg/1

where group 1 gets the lines.