in reply to regex whitespace quantifers

Hello halak77, and welcome to the Monastery!

Yes, the \s* is greedy, but if no match is found then the regex engine backtracks. So it tries to match the line:

# This comment has one leading space

with one space character, but fails because the following character (#) doesn’t match [^#]. So the engine backtracks and tries zero whitespace characters, followed by [^#], which succeeds because the first character (a space) is not a hash, and so matches [^#].

If I replace my regex with /^\s*[^#\s]... it works as desired.

Yes, because now the case where a space matches the no-hash character class is explicitly excluded.

On the working of the Perl regex engine, see the section “The Little Engine That /Could(n't)?/” in The Camel Book (4th Edition, 2012), pages 241–246.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,