CRLF in RegEx

good morning people,

I’m learning to use RegEx, I’m doing pretty good, but I cannot find how to deal with CRLFs in the source string.

easy example that I tried:

$string = ‘string on one line’
$regex = ‘.+(on one).+’
$string -match $regex

True

$string = @’
string
on two line
'@
$regex = ‘.+(on two).+’
$string -match $regex

False

how can I build my RegEx so that it will work on a 2 lines string?

thanks!

For . to match newline characters, you must be in single-line mode. This can be activated in a regex string by prefixing the match string with (?s).

$string = @'
string
on two line
'@
$regex = '(?s).+(on two).+'
$string -match $regex

[quote quote=249341]For . to match newline characters, you must be in single-line mode. This can be activated in a regex string by prefixing the match string with (?s).

$string = @‘ string on two line ’@ $regex = ‘(?s).+(on two).+’ $string -match $regex[/quote]
well, that was easy.

thanks!