Regex - multi-line task

I think I burned out, and therefore I do not see a clear mistake. Anyway, I want the following regular expression:

#BIZ [. \ S] * # ENDBIZ

to capture me with the #BIZ tag, the #ENDBIZ tag and all the text between the tags. For example, if you need some text, I want the expression to match:

#BIZ
some text some test
more text
maybe some code
#ENDBIZ

Currently, the regular expression does not match anything. What have I done wrong?

EXTRA DATA

I am doing the following in PHP

preg_replace ('/ # BIZ [. \ s] * # ENDBIZ /', 'my new text', $ strMultiplelines);

+3
source share
8 answers

- , [.\s] " ". , [\s\S], "match whitespace non-whitespace".

preg_replace('/#BIZ[\s\S]*#ENDBIZ/', 'my new text', $strMultiplelines);

: :

. (?) , , . () - - [\s\S], [\w\W] [\d\D]. , , , , , \s , .

, , . , , , ^, -, \ ]. "Metacharacters Inside Character Classes" Regular-Expressions.info.

+13
// Replaces all of your code with "my new text", but I do not think
// this is actually what you want based on your description.
preg_replace('/#BIZ(.+?)#ENDBIZ/s', 'my new text', $contents);

// Actually "gets" the text, which is what I think you might be looking for.
preg_match('/(#BIZ)(.+?)(#ENDBIZ)/s', $contents, $matches);
list($dummy, $startTag, $data, $endTag) = $matches;
+2

#BIZ [\ s\S] * # ENDBIZ

+2

, , , , re.DOTALL Python. , ?

+1

- [.\s], ( ) . , .* . . , ((?s:) .NET regex).

(?s:#BIZ.*?#ENDBIZ)
+1

- , , Perl /m /s ? , , , ?!

0

preg_replace('/#BIZ.*?#ENDBIZ/s', 'my new text', $strMultiplelines);

The 's' modifier says: "Match a dot with anything, even a newline." '?' says, not greedy, for example, for the case:

foo

#BIZ
some text some test
more text
maybe some code
#ENDBIZ

bar

#BIZ
some text some test
more text
maybe some code
#ENDBIZ

hello world

non-greed will not get rid of the "bar" in the middle.

0
source

It looks like you're using a javascript regex, you need to enable multi-line by specifying a flag mat the end of the expression:

var re = /^deal$/mg 
-1
source

Source: https://habr.com/ru/post/1709247/


All Articles