带有 2 个下划线和 3 个段的文件名的正则表达式

Regex expression for file name with 2 underscores and 3 segments

我需要一个 regex 表达式,它将 select 属性文件列表中具有特定文件名格式的文件。
我需要 select 个具有以下文件格式的文件名的文件:

<app_name>_<app_version>_<environment>.properties

它们一起用 2 个下划线绑定,如下所示:-

<A-Z/a-z/0-9/special char>_<A-Z/a-z/0-9/special char/float value>_<A-Z/a-z/0-9/special char>.properties

文件名始终包含2个下划线_,下划线之间可以是任意字符串。
例如,以下是 有效 可以 select 编辑的文件名:

app1_1.0_prod1.properties
app2_2_prod2.properties
app_vers1_prod.properties
app-1_vers1_prod-2.properties
asd_efg_eee.properties

可以是字母或数字或特殊字符或它们之间的组合,下划线之间.
请注意,文件名中只能有2个下划线_
2 个下划线 _ 以外的任何内容都不是有效的文件名,不会被 select 编辑,文件名应始终将这 3 个部分由 2 个下划线 _
分隔 以下是无效 文件名:

abc.properties
abc.123.efg.properties
as_1.efg.ddd.rr.properties
ee_rr.properties
_rr_.properties

我尝试了以下正则表达式:

[^_]*\.[^_].properties  

但不工作。也许这是错误的。我没有得到这个的线索。 请帮我创建这个正则表达式。
谢谢

我认为/^[^_]+_[^_]+_[^_]+\.properties$/应该能满足您的要求:

const tests = [
  'app1_1.0_prod1.properties',
  'app2_2_prod2.properties',
  'app_vers1_prod.properties',
  'asd_efg_eee.properties',
  'abc.properties',
  'abc.123.efg.properties',
  'as_1.efg.ddd.rr.properties',
  'ee_rr.properties',
  '_rr_.properties'
];

tests.forEach(test => { 
  console.log(test, /^[^_]+_[^_]+_[^_]+\.properties$/.test(test)); 
});

或者,您可以使用 /^([^_]+_){2}[^_]+\.properties$/

如果你想收紧 . 的使用,那么我想你想要

/^[^_.]+_([^_.]+|\d+(\.\d+)?)_[^_.]+\.properties$/

这应该可行,因为每个部分基本上可以包含除下划线以外的任何字符:/[^_]*_[^_]*_[^_]\.properties/