A
A
Al2016-06-22 10:45:07
JavaScript
Al, 2016-06-22 10:45:07

Why doesn't RegExp take into account line breaks?

I wrote a regular expression new RegExp('(<%--)(.*)(--%>)','gim') , which should find everything that is enclosed in the character sequence <%-- --%> . Within a single line, this works fine, but if there is a line break between the <%-- --%> character sequences , then everything will break. I decided to catch the line break with this regular expression: (<%--)([\s\S]*)(--%>), but it does not work correctly.
Tell me how to write a regular expression that will take into account line breaks?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Al, 2016-06-22
@Sanu0074

(<%--)([\s\S]*?)(--%>)

A
Alexey Ukolov, 2016-06-22
@alexey-m-ukolov

Decimal point denotes any character except newline
javascript.ru/regexp
Accordingly, the regular expression should be as follows: /(<%--)((?:.|\n)*)(--%>)/gmi.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question