Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Doesn't This Regexp work?

Here is the regexp: /<\?nib.+\?>/im

I'm testing it on a file like this:

<html>

<head>
<title>OPEN LARK</title>
</head>

<body>
<h1>THIS IS A HEADER 

    <?nib   
             asdf
    ?>
</h1>
</body>

</html>

I am getting no matches. How can I fix this?

like image 323
turnt Avatar asked Feb 14 '26 08:02

turnt


2 Answers

You are using the . to match multilines. That isn't implemented in Javascript. Check this answer for a workaround.

About the workaround:

Instead of the dot, use a class and its negation to match everything. For example, replace the . with [\s\S].

like image 67
Racso Avatar answered Feb 16 '26 20:02

Racso


because the dot (.) doesn't match newlines.

The way in javascript is to replace the dot by [\s\S]

like image 27
Casimir et Hippolyte Avatar answered Feb 16 '26 20:02

Casimir et Hippolyte



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!