vbs regex:仅匹配前两个下划线之间的文本

问题描述

| 我正在用VBS进行一些文件名抓取,如果文件名被调用
hello_world_2012_is_not the end of the world.pdf
那么正则表达式应该与单词“ world”匹配,其他都不能匹配。 我尝试了这个:
[_][^_]+(?=_)
但是它得到的是介于两个下划线之间的所有内容。如何只选择第一次出现?     

解决方法

我建议以下正则表达式:
/^[^_]*_([^_]*)_/
说明:
^        # Anchor the search to the start of the string
[^_]*    # Match any number of non-underscores,don\'t capture them
_        # Match the first underscore
([^_]*)  # Match any number of non-underscores,do capture them
_        # Match the second underscore.
然后第一个捕获组(
$1
)将包含
world
,并且正则表达式与字符串中的其他任何地方都不匹配。     ,正则表达式本身应如下所示:
_([^_]*)_
该字符串被捕获到组1中。 或者,使用字符串函数找到前两个下划线,然后提取它们之间的内容。     

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...