regex - powershell中带下划线的同一个词

标签 regex string powershell

我有 2 个表达式,用下划线分隔。我无法创建允许我区分它们的正则表达式。

例子:

"S_Macdo" -match "^S(?<NAME>[a-zA-Z]*)"

-> Macdo -> 确定

"S_Macdo_Fries" -match "^S(?<NAME>[a-zA-Z]*)"

-> Macdo -> NOK - 我需要 Macdo_Fries

谢谢

最佳答案

你可以使用

^S_(?<NAME>[a-zA-Z_]*)

参见 online .NET regex demo

详情

  • ^ - 字符串开始
  • S_ - 文字子串
  • (?<NAME>[a-zA-Z_]*) - 捕获 0 个或多个 ASCII 字母或下划线字符的“NAME”组。

关于regex - powershell中带下划线的同一个词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52720542/

相关文章:

java - html 中 Java 代码的语法高亮

c++ - 通过从文件中读取来 boost 正则表达式匹配

linux - 通过 bash 在文件中搜索字符串,但只能匹配

c++ - 从输入迭代器创建 C++ std::string 的性能

python - 循环处理字符串

powershell - '<' 运算符保留供将来使用

c# - 替换某些字符之间的值

regex - 匹配语法问题

powershell - 如何在 PowerShell 脚本中创建命名空间

powershell - 如何使用 Powershell 2.0 版解压缩 Zip 文件?