in reply to Regex Parsing Chars in a Line
Did you mean "first and last hyphen" ? If so:
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11109157 use warnings; my $line = 'A A Milne - Winnie-The-Pooh and Silver-Bear vol5-12 - Xi P +ress - Peking (1998)'; print "$line\n"; $line =~ s/-\K.*(?=-)/ $& =~ tr'-'_'r /e; print "$line\n";
Outputs:
A A Milne - Winnie-The-Pooh and Silver-Bear vol5-12 - Xi Press - Pekin +g (1998) A A Milne - Winnie_The_Pooh and Silver_Bear vol5_12 _ Xi Press - Pekin +g (1998)
If this is not what you want, how about providing several test cases along with expected output.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex Parsing Chars in a Line
by kel (Sexton) on Nov 26, 2019 at 05:16 UTC | |
by AnomalousMonk (Archbishop) on Nov 26, 2019 at 07:53 UTC |