in reply to Regex: not the trailing whitespace

Just delete the trailing whitespace first.

while (<>) { s/\s+\z//; ... }

The second is a look-back assertion so the final trailing whitespace won't just be eaten by the main item

Huh? /[*#]+:?/ cannot eat the trailing whitespace.

So all you need is

/ ^ \s* ([*#]+:?) \s* (.*\S)? \s* $ /sx

(Is some backtracking protection needed?)

Replies are listed 'Best First'.
Re^2: Regex: not the trailing whitespace
by John M. Dlugosz (Monsignor) on Apr 23, 2011 at 06:48 UTC
    Huh? /[*#]+:?/ cannot eat the trailing whitespace.
    No, I mean the (.*) would. The leading string of bullets is the prefix, and the content of the line after that is the "main item".

      No, I mean the (.*) would.

      There is no /(.*)/ in your code. If you mean the /(.*\S)/, it can't eat the trailing whitespace either.

        I was explaining why I added \S to the end. The naive solution, a FAQ here, is (.*)(somethingelse).