in reply to Re: Simple Regex drives me insane
in thread Simple Regex drives me insane

Thank you very much for you answer. It works but there is a problem: I would to successfully match the string if '#foo' is not there (0 or 1 occurences)

Replies are listed 'Best First'.
Re^3: Simple Regex drives me insane
by ikegami (Patriarch) on Mar 30, 2024 at 17:38 UTC

    It already does do that.

    Specifically, it always matches, setting $1 to foo if #\w+ is found at the start of the string, and setting $1 to undef otherwise.

      That said, I believe it has other problems.

      It doesn't set $1 to foo when matching against bli #foo bla.

      It doesn't set $1 to the empty string when matching against bli bla. However, it does set it to undef, which might be close enough.