正则表达式 - 如果通过测试文件名,则测试扩展名

时间:2017-05-23 02:22:54

标签: javascript regex

如果文件名通过扩展测试,是否可以在regex中检查文件名, 我有regex匹配.local.txt的文件,例如something.localsomething.txt。在测试中是否有严格的文件名?

目前我正在使用/\.(?:local|txt)$/,但不知道如何实施该条件。 例如文件名是 test.raw.local 所以我想检查它是否有raw.local然后忽略该文件。 我试着/\.(?:local|txt|!raw.local)$/但是没有工作!!

valid:

- > test.local,hello.txt,script.something.local

invalid:

- > test.raw.local

1 个答案:

答案 0 :(得分:1)

除了你想要的字符串断言之外,你还可以使用负向前瞻:

(?!.*\.raw\.local$)^.+\.(?:local|txt)$

Regex101 Example