从多行字符串中提取字符串

时间:2019-01-03 17:05:22

标签: powershell

我想提取}$s = 'abc { 123 }' $s -match 'abc {(.*?)' # true $s -match 'abc {(.*?)}' # false, expect true 之间的内容。

{{1}}

但是,似乎没有进行多行匹配吗?

1 个答案:

答案 0 :(得分:1)

.仅在SingleLine模式下执行正则表达式操作时才与换行符匹配。

您可以使用(?[optionflags])添加一个regex option at the start of your pattern

$s -match 'abc {(.*?)}'       # $False, `.` doesn't match on newline
$s -match '(?s)abc {(.*?)}'   # $True, (?s) makes `.` match on newline
相关问题