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?

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.