简体   繁体   English

如何制作有效的多行Javascript REGEX

[英]How do I make a valid multiline Javascript REGEX

I have a block of text that can literally be anything. 我有一小段文字可以说是什么。 Somewhere in the text is something like [block] or [header]. 文本中的某处类似于[block]或[header]。 I want to match against the following regex: 我想匹配以下正则表达式:

new RegExp("(.*)\\\\[" + config.wrapper+ "\\\\](.*)", "m");

If I write "hello[block]" it works perfect. 如果我写“ hello [block]”,它会完美。

If I write "hello 如果我写“你好

[block]" it catches nothing. [block]“它什么也没捉住。

What am I missing to properly match? 我错过了什么才能正确匹配?

Note, for complicated reasons, I can't currently use a template engine like handlebars or any of those in this special case. 请注意,由于复杂的原因,我目前无法使用模板引擎,如把手或此特殊情况下的任何一个。

Change this: 改变这个:

(.*)

to this: 对此:

([\\s\\S]*)

because the . 因为. doesn't match line breaks. 与换行符不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM