Regex:过滤掉预发布标签

Regex:过滤掉预发布标签,regex,powershell,Regex,Powershell,我有一些标签: tag-4.2.23.1 tag-4.2.23-beta.1.365 tag-4.2.23 我试图构建一个正则表达式来过滤掉标签-4.2.23-beta.1.365 到目前为止,我已经完成了以下工作: 4\.2\.23[^-] 但是在PowerShell中使用它时 $tags | Where-Object {$_ -match $regex } 它只给出了标记-4.2.23.1您需要匹配字符串边界。例如,你可以有一个非常通用的 /\A\w+-\d+(\.\d+)*\z/ 扩

我有一些标签:

tag-4.2.23.1
tag-4.2.23-beta.1.365
tag-4.2.23
我试图构建一个正则表达式来过滤掉标签-4.2.23-beta.1.365

到目前为止,我已经完成了以下工作:
4\.2\.23[^-]

但是在PowerShell中使用它时

$tags | Where-Object {$_ -match $regex }

它只给出了
标记-4.2.23.1

您需要匹配字符串边界。例如,你可以有一个非常通用的

/\A\w+-\d+(\.\d+)*\z/
扩大:

/(?x)       # (freespacing marker)
  \A        # start of string
  \w+       # initial tag name (change it if tags can contain non-word characters)
  -         # separator dash
  \d+       # major version number
  (\.\d+)*  # other parts of the version. Change the quantifier if needed
            # for instance to {2,3} to match only 3- and 4-part versions.
  \z        # end of string
/
或者有一个非常具体的

/\Atag-4\.2\.23(\.\d+)?\z/

要仅匹配
4.2.23

之后的可选子批次号,您能否提供完整的相关代码以重新发布?此外,在这里,向前看更合适,
4\.2\.23(?)
,或者更好,
\b4\.2\.23(?)