Regex to match only the first line?

that’s sounds more like a job for the filehandle buffer.

You should be able to match the first line with:

/^(.*)$/m

(as always, this is PCRE syntax)

the /m modifier makes ^ and $ match embedded newlines. Since there’s no /g modifier, it will just process the first occurrence, which is the first line, and then stop.

If you’re using a shell, use:

head -n1 file

or as a filter:

commandmakingoutput | head -n1

Please clarify your question, in case this is not wat you’re looking for.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)