javascript - 分隔符与换行符之间字符串的正确正则表达式是什么
问题描述
用换行符捕获分隔符之间的字符串的正则表达式是什么。
字符串是:
/* start \*/This is a test of regex
带有新行和(特殊字符)
asdsadasd/* end*/
请建议一个输出的正则表达式:- ***这是一个带有新行和(特殊字符)的正则表达式测试
asdsadasd
即 /* 开始 */ 和 /* 结束 */ 之间的字符串。
Here **/* start */** and **/\* end */** are the **delimiters**.
解决方案
您可以使用[^]*?
.
例子:
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]);
推荐阅读
- python - 为什么 DLL 作为模块导入在 Python2 中有效,而在 Python3 中无效?
- control-m - 是否可以在 Control-M 的可自定义过滤器中使用 AutoEdit 变量?
- wordpress - 子主题不使用子翻译文件
- django-rest-framework - 如何以安全的方式为 UserList 设置权限类
- laravel - 如何从资源文件夹动态加载资产到公用文件夹并使用asset()助手访问它们
- linux - 为 Azure Pipeline 脚本 STP 打开端口
- rolling-computation - 如何使用由 dolphindb 中的体积总和确定的窗口长度进行滚动窗口计算
- python - 执行校准时 cv2.cornersubpix() 的好处有多大?
- python - 在python中re.split()之后删除左右任何空白
- android - Android上的自定义蓝牙堆栈