in reply to remove chars with regex
The error come from using = when you meant to use =~.
But the pattern is also wrong. There will never be 5 non-space characters before the first character of the string, for starters.
Fixed:
my ( $output ) = $char =~ /(?<=^\S{5})(\S+)(?=\S{5}\z)/;
There's really no point in using look-arounds or \S, though.
my ( $output ) = $char =~ /^.{5}(.*).{5}\z/s;
Faster and cleaner:
my $output = substr( $char, 5, -5 );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: remove chars with regex
by ForgotPasswordAgain (Vicar) on Feb 27, 2025 at 03:07 UTC | |
by ikegami (Patriarch) on Feb 27, 2025 at 11:18 UTC |