0

I want to extract the content between abc { and }.

$s = 'abc {
    123
}'
$s -match 'abc {(.*?)' # true
$s -match 'abc {(.*?)}' # false, expect true

However, it seems it doesn't do multiple line match?

ca9163d9
  • 27,283
  • 64
  • 210
  • 413

1 Answers1

1

. will only match on newline characters when you perform a regex operation in SingleLine mode.

You can add a regex option at the start of your pattern with (?[optionflags]):

$s -match 'abc {(.*?)}'       # $False, `.` doesn't match on newline
$s -match '(?s)abc {(.*?)}'   # $True, (?s) makes `.` match on newline
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206