Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl regular expression to match the first instance of ? across multiple lines

I am trying to parse an e-mail reply using regular expressions. My response looks like:

This is my response.
Some text here

?



?



From: Lastname, Firstname

Sent: Saturday, January 05, 2013 7:37 PM

To: Lastname, Firstname

Subject: Some Subject



?



Some Text

I am interested in parsing everything up to the first ?. I have tried utilizing single line mode with $response =~ /^(.*)\?\n/s;. But that returns me everything up to the last ?. Any help would be appreciated.

like image 747
kamix Avatar asked Jan 30 '26 18:01

kamix


1 Answers

.* is greedy. The non-greedy version .*? should work.

like image 134
pemistahl Avatar answered Feb 02 '26 09:02

pemistahl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!