简体   繁体   English

使用正则表达式在多义字符之间获取文件名

[英]Getting filename between multipal special characters using Regex

I'm trying to fetch the file names which are in between multiple special character like '$$' ( example $$yaktocat.png$$) , i think it's better to ignore single special character $, if not we cannot use that character inside the file. 我正在尝试获取介于多个特殊字符之间的文件名,例如'$$'(例如$$ yaktocat.png $$),我认为最好忽略单个特殊字符$,否则我们不能使用该字符在文件中。

sample data 样本数据

img src="$$yaktocat.png$$" alt="this is yaktocat image"

Regex trying to use 正则表达式尝试使用

(\$+?(.*?)\$+?)

but still that match the single instance also 但仍然与单个实例匹配

Do: 做:

\$\$([^$]*)\$\$

Now the only captured group, ([^$]*) , will have the desired filename (eg yaktocat.png ), surrounded by $$ s. 现在,唯一捕获的组([^$]*)将具有所需的文件名(例如yaktocat.png ),并用$$包围。

Demo 演示版

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

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