结束的所有文件的正则表达式是什么
"*.med"但不是
"*.result.med"?
我试过了
((?!.result.med).med$)没有成功。 我确实给了所有.med文件,包括.result.med文件。
What is the regular expression for all files which end on
"*.med"but not
"*.result.med"?
I tried
((?!.result.med).med$)without success. I does give all .med files including .result.med files.
最满意答案
你需要一个lookbehind而不是lookahead: ^.*(?<!\.result)\.med$ 您的前瞻不起作用,因为对于文件*.result.med ,当正则表达式引擎在最后一个点之前定位时,它会检查是否存在.result.med (没有,因为.med内容是.med )然后匹配.med$ 您也可以通过前瞻来做到这一点,但您需要这样做: ^(?!.*\.result.med$).*\.med$
You need a lookbehind instead of a lookahead here : ^.*(?<!\.result)\.med$ Your lookahead does not work because for a file *.result.med, when the regex engine positionned just before the last dot, it checks if there is .result.med (there isn't, because what follows is .med) then matches .med$ You can also do this with a lookahead, but you need to do it this way : ^(?!.*\.result.med$).*\.med$
正则表达式文件扩展名(Regular expression file extensions)结束的所有文件的正则表达式是什么
"*.med"但不是
"*.result.med"?
我试过了
((?!.result.med).med$)没有成功。 我确实给了所有.med文件,包括.result.med文件。
What is the regular expression for all files which end on
"*.med"but not
"*.result.med"?
I tried
((?!.result.med).med$)without success. I does give all .med files including .result.med files.
最满意答案
你需要一个lookbehind而不是lookahead: ^.*(?<!\.result)\.med$ 您的前瞻不起作用,因为对于文件*.result.med ,当正则表达式引擎在最后一个点之前定位时,它会检查是否存在.result.med (没有,因为.med内容是.med )然后匹配.med$ 您也可以通过前瞻来做到这一点,但您需要这样做: ^(?!.*\.result.med$).*\.med$
You need a lookbehind instead of a lookahead here : ^.*(?<!\.result)\.med$ Your lookahead does not work because for a file *.result.med, when the regex engine positionned just before the last dot, it checks if there is .result.med (there isn't, because what follows is .med) then matches .med$ You can also do this with a lookahead, but you need to do it this way : ^(?!.*\.result.med$).*\.med$
发布评论