首页 > 解决方案 > 分隔符与换行符之间字符串的正确正则表达式是什么

问题描述

用换行符捕获分隔符之间的字符串的正则表达式是什么。

字符串是:

/* start \*/This is a test of regex

带有新行和(特殊字符)

asdsadasd/* end*/

请建议一个输出的正则表达式:- ***这是一个带有新行和(特殊字符)的正则表达式测试

asdsadasd

即 /* 开始 */ 和 /* 结束 */ 之间的字符串。

Here **/* start */** and **/\* end */** are the **delimiters**.

标签: javascriptregex

解决方案


您可以使用[^]*?.

例子:

var string = `/* start */This is a test of regex

with new line and (special char)

asdsadasd/* end */`;

var result = string.match(/\/\*\ start \*\/([^]*?)\/\* end \*\//);

console.log(result[1]);


推荐阅读