Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 如何使用多行字符串中的多行正则表达式命名捕获_Regex_Powershell_Multiline - Fatal编程技术网

Regex 如何使用多行字符串中的多行正则表达式命名捕获

Regex 如何使用多行字符串中的多行正则表达式命名捕获,regex,powershell,multiline,Regex,Powershell,Multiline,我知道如何在一系列行上使用命名捕获,但是。。。如何在多行字符串上使用命名捕获 $herestring = @" Foo Bar Foo Manchu "@ $pattern = [regex]'(?s)(?<Foo>Foo\s+\w+)' 现在怎么办?现在按名称获取组$herestring | Select String-Pattern$Pattern-AllMatches |%{$$.Matches}{$$.Groups['Foo'].Value}另一

我知道如何在一系列行上使用命名捕获,但是。。。如何在多行字符串上使用命名捕获

$herestring = @"
Foo
  Bar
    Foo
      Manchu
"@ 

$pattern = [regex]'(?s)(?<Foo>Foo\s+\w+)'

现在怎么办?

现在按名称获取组
$herestring | Select String-Pattern$Pattern-AllMatches |%{$$.Matches}{$$.Groups['Foo'].Value}
另一种方法:
$Pattern.Matches($herestring){$.Groups['Foo'].Value}
我在查看[]的结构,仅查看对象的属性(组)就不太明显了因为那里似乎什么都没有。深入研究括号的结构及其用法,它似乎在访问哈希表键的值,对吗?哈希表键如下所示:
$hash[“name”]
,但如果是,您也应该能够编写此项:
$\uuu.Groups.Foo
——但这不起作用。我不确定这是什么样的结构,但它是有效的。谢谢。现在请按姓名分组
$herestring | Select String-Pattern$Pattern-AllMatches |%{$$.Matches}{$$.Groups['Foo'].Value}
另一种方法:
$Pattern.Matches($herestring){$.Groups['Foo'].Value}
我在查看[]的结构,仅查看对象的属性(组)就不太明显了因为那里似乎什么都没有。深入研究括号的结构及其用法,它似乎在访问哈希表键的值,对吗?哈希表键如下所示:
$hash[“name”]
,但如果是,您也应该能够编写此项:
$\uuu.Groups.Foo
——但这不起作用。我不确定这是什么样的结构,但它是有效的。谢谢
$herestring | Select-String -Pattern $pattern -AllMatches | % { $_.Matches }