luckysummer has asked for the wisdom of the Perl Monks concerning the following question:

I want print out the match vaule.

But Perl will make B[0] become B0.

Is there any way to slove it?

please help, thanks.

my $line = 'pin B[0] 10'; my $inputName = 'B[0]'; if($line =~ m/[\w]+[\s]+$inputName[\s]+([\.\d]+)/){ print "$1\n"; }

Replies are listed 'Best First'.
Re: Regular expression & raw data
by Eily (Monsignor) on Apr 07, 2017 at 08:34 UTC

    Yes, quotemeta will escape the metacharaters in a string to cancel their special regex meaning.
    my $inputName = quotemeta 'B[0]';

      I got it, thank you.:-)
Re: Regular expression & raw data
by haukex (Archbishop) on Apr 07, 2017 at 08:37 UTC
      It's useful, thank you.:)
Re: Regular expression & raw data
by Anonymous Monk on Apr 07, 2017 at 08:34 UTC