【发布时间】:2019-01-03 17:05:22
【问题描述】:
我想提取abc { 和} 之间的内容。
$s = 'abc {
123
}'
$s -match 'abc {(.*?)' # true
$s -match 'abc {(.*?)}' # false, expect true
但是,它似乎不做多行匹配?
【问题讨论】:
标签: powershell
我想提取abc { 和} 之间的内容。
$s = 'abc {
123
}'
$s -match 'abc {(.*?)' # true
$s -match 'abc {(.*?)}' # false, expect true
但是,它似乎不做多行匹配?
【问题讨论】:
标签: powershell
当您在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
【讨论】: