预匹配来自 html 内容的文件名
Preg match filenames from html content
此表达式在 html 内容中查找包含数字、字母和下划线的文件名。
preg_match_all('/(\w+\.\w{2,4})/', $content);
但是没有找到像file-name.txt这样的文件名。如何更改表达式以查找包含破折号和其他合法字符的文件名?
假设文件后缀不包含 non-letters/digits: [\w-]
之类的字符 class 不适合您吗?您到底尝试了什么?
preg_match_all('/([\w-]+\.\w{2,4})/', $content);
对我有用 file-name.txt
这样的文件名
注意:连字符必须在末尾,否则 class 的字符范围假定为 PHP。
此表达式在 html 内容中查找包含数字、字母和下划线的文件名。
preg_match_all('/(\w+\.\w{2,4})/', $content);
但是没有找到像file-name.txt这样的文件名。如何更改表达式以查找包含破折号和其他合法字符的文件名?
假设文件后缀不包含 non-letters/digits: [\w-]
之类的字符 class 不适合您吗?您到底尝试了什么?
preg_match_all('/([\w-]+\.\w{2,4})/', $content);
对我有用 file-name.txt
注意:连字符必须在末尾,否则 class 的字符范围假定为 PHP。