我正在尝试从长文本中提取文件名.
Page source.html鉴于以下文字:
Page source file:///somedir/subdir/subdir/mysource.html lorem ipsum more text
Lorem Ipsum ...
Lorem Ipsum Page source file:///anotherdir/sub/dir/anothersource.html
Run Code Online (Sandbox Code Playgroud)
我想要一个所有文件名的列表:
mysource.html
anothersource.html
Run Code Online (Sandbox Code Playgroud)
我一直在尝试使用以下正则表达式:
// this only gets the last one (because of the greedy .*)
Page source.*\/(.*\.html)
// This gets all occurrences, but the value in my capture group is the
// complete path starting after the first occurrence of /
Page source.*?\/(.*?\.html)
Run Code Online (Sandbox Code Playgroud)
我怎么能告诉正则表达式引擎对外表达式不贪婪,但仍然贪婪到最后/才能到达该.html部分之前?
Page source.*?([^\/]+?\.html)
Run Code Online (Sandbox Code Playgroud)
演示:https://regex101.com/r/uX6fY2/2