On 2/23/02 8:51 PM, Marc Morrison <[EMAIL PROTECTED]> wrote:

Hi Marc,

> The form generally has input as follows:
> 
> Comment:  comment 1 then a new line
> then comment two then a new line
> then comment three
> 
> I am trying to capture all three lines of this
> Comment: field.

Oops, sorry about that.

> The script looks like:
> 
> $/ = undef;
> while <>;
> if /^Comment:(\s*)(\w*)/
> print $2;

I assume that's not the real code, as it doesn't compile :)

I'd try something like this, assuming your comments are in $_:

##### START CODE #####

/^Comment:\s*(.*?)(?:\n\n|\z)/ms;

print $1;

##### END CODE #####

'(.*?)' is a non-greedy match (it'll take the shortest possible match, which
would be nothing, were it not for the rest of the regex). '(?:\n\n|\z)' then
matches either two newlines or the end of the string (you may want to adjust
this). The 'm' option, as before, allows '^' to match on the start of line,
instead of just the start of the string. The 's' option allows '.' to match
newlines, allowing for multiline matches.

There might be a more efficient way to do this, but it took me a little
while to even figure out how to do it, so I'm not aware of a better way
right now.

Hopefully I understood it correctly this time :)

Hope that helps,

-- 
Michael


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to