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

It doesn't set $1 to the foo when matching against #foo bli bla, despite an example stating it should.

It doesn't set $1 to the empty string when matching against bli bla, despite an example stating it should.

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

For the last two, it doesn't match and leaves $1 unchanged.


Update: After the update to the parent, the following holds:

It doesn't set $1 to the foo when matching against #foo bli bla, despite an example stating it should.

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.

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

Replies are listed 'Best First'.
Re^3: Simple Regex drives me insane
by Timka (Acolyte) on Mar 30, 2024 at 18:43 UTC

    I updated my last reply

    But I think it might be better to step back and consider what you are trying to achieve.

    If you can use code, that may be simpler:

    my $in = "foo"; my $out = $in =~ /#(.*)/ ? $1 : "";

      I'm not the OP.

      The .* should be \S*, \S+, \w*, \w+ or something. It's unclear what should be used exactly, but .* matches too much.

      The above also applies for the first .* in your edited code.

      The second .* in your edited code is useless. You could just leave it out.