in reply to Search and replace regex, but only retain a portion of the string
#!/usr/bin/perl -l # https://perlmonks.org/?node_id=1227618 use strict; use warnings; my $want = q{UK_Mobile_Vodafone_GBRVF}; my $dest = q{UK Mobile - Vodafone [GBRVF] [MSRN]}; print $dest; $dest =~ s/( )|- |\[|\].*/ '_' x !!$1 /ge; print $dest; print $want;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Search and replace regex, but only retain a portion of the string
by ghenry (Vicar) on Dec 23, 2018 at 13:43 UTC |