From: luke (dot) Date: 2005-09-05T08:51:27+09:00 Subject: Making my Regex less greedy? Hi, I'm working on a regular expression that will chop a posted message in half, but chop it on a new paragraph break. I've decided it should look for the new paragraph break after 100 characters. I'd like the regular expression to choose an earlier paragraph break rather than a later one, but at the moment, if there is a message with a number of paragraphs, it chooses the last possible one it can in order to make a match. I remember reading in the Pickaxe about how regular expressions are 'greedy', and wonder if this is a case of regex gluttony perhaps and what I can do to recommend to it a lighter diet. # final act is to chop message in half if message =~ /\A(.{100,#{message.length}})<\/p>\s*

(.*)/m then first_half = $1 second_half = "

\n

" + $2 else first_half = message end The logic I'd like the above regex to operate with is: "Starting 100 characters into the message, chop the message at the next paragraph break". Thanks Luke