regex - 在 powershell 选择字符串输出中删除以 *(asterisk) 开头的行

标签 regex powershell

我正在编写一个代码,以便它找到具有 $control 但应该删除第一列以 * 开头的行

我正在与以下人员合作,但似乎不起作用..

  $result = Get-Content $file.fullName | Select-String $control | Select-String -pattern "\^*" -notmatch

提前致谢

最佳答案

你在逃避错误的角色。你不想逃^因为那是你“开始于”的 anchor 。你会想逃避星号,所以试试这个:

$result = Get-Content $file.fullName | Select-String $control | select-string -pattern "^\*" -notmatch

另外,如果你想要的只是线条,你也可以使用这个:
Get-Content $file.fullName | ? { $_ -match $control -and $_ -notmatch '^\*'}

关于regex - 在 powershell 选择字符串输出中删除以 *(asterisk) 开头的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17000330/

相关文章:

regex - urlrewrite 中 $1 之后的数字

xml - 遍历子节点

powershell - 从FileInfo对象获取目录名称

c++ - Boost:regex_search - 匹配括号之间的字符串

regex - 如何使用awk轻松过滤日志?

powershell - 如何仅从PowerShell中的哈希表获取值?

powershell - 算术运算符的问题

PowerShell 获取从本周五开始的 12 个月的周五

php - 正则表达式解析视频持续时间字符串

javascript - 鼠标悬停时替换部分 URL 以获取原始尺寸图像