in reply to Re^2: Wildcard in a hash
in thread Grep asterisk sign in input file
See perlre. In perl regular expression syntax, the asterisc * is a quantifier which means "zero or more times" .
So, in c4*_123 the asterisc would mean "zero or more times 4". To make the * into a wildcard, preceed it with a period, which means "any character". In my previous answer in this thread, there was the line
$pins2 =~ s/\*$/.*/; # make key into regex string if trailing *
The dollar sign after the escaped asterisc is an end anchor, so this matches only an asterisc at the end of the string. To match the asterisc anywhere, just remove the end anchor:
$pins2 =~ s/\*/.*/; # make key into regex string if containing *
If your keys can contain more than one asterisc, add the /g modifier (global) to the s///:
$pins2 =~ s/\*/.*/g; # make key into regex string if containing *
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Wildcard in a hash
by DespacitoPerl (Acolyte) on Aug 16, 2017 at 02:25 UTC | |
by shmem (Chancellor) on Aug 16, 2017 at 06:16 UTC | |
by DespacitoPerl (Acolyte) on Aug 17, 2017 at 09:38 UTC |