Regex to return string - Why match is greedy?

Now I have an idea what you want.
The ^ must be at the beginning of the RE in order to mark the beginning of the line.
I see you have a multi-line block captured in a variable (that is, sigh, certainly not the best idea in shell).
A RE (here, ERE) is not made for multi-line and embedded newline characters. Nevertheless you can try if a literal newline works:

regex_needle=".*
$space\); *
"

Or with a nl variable:

nl=$'\n'
regex_needle=".*${nl}$space\); *${nl}"
1 Like