17

I'm trying to accomplish the same thing as seen here:

i.e. assuming you have a text like:

<p>something</p>

<!-- OPTIONAL -->

<p class="sdf"> some text</p>
<p> some other text</p>

<!-- OPTIONAL END -->

<p>The end</p>

What is the regex that would match:

<p class="sdf"> some text</p>
<p> some other text</p>

I've setup a live test here using:

<!-- OPTIONAL -->(.*?)<!-- OPTIONAL END -->

but it's not matching correctly. Also the accepted answer on the page didn't work for me. What am I missing?

Community
  • 1
  • 1
rtuner
  • 2,312
  • 3
  • 24
  • 36
  • the required `/s` modified is [not available in JavaScript](http://www.regular-expressions.info/javascript.html) – Aprillion Jun 23 '14 at 22:25
  • I fixed the formatting of your post so we can see the actual regex you used, and I disabled syntax highlighting on that part to reduce confusion. I don't know why you had backslashes before the opening angle brackets (`\ – Alan Moore Jun 23 '14 at 23:16

1 Answers1

34

Well unfortunately, RegExr is dependent on the JS RegExp implementation, which does not support the option to enable the flag/modifier that you need.

You are looking for the s (DotAll) modifier forcing the dot . to match newline sequences.

If you are using JavaScript, you can use this workaround:

/<!-- OPTIONAL -->([\S\s]*?)<!-- OPTIONAL END -->/
hwnd
  • 67,942
  • 4
  • 86
  • 123