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
  • 24,345
  • 44
  • 175
  • 352

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
  • 135,435
  • 9
  • 130
  • 184