in reply to Re^4: Please correct me in the above regular expression
in thread Please correct me in the above regular expression
I surrender. One way:
Win8 Strawberry 5.8.9.5 (32) Sun 03/21/2021 4:04:08 C:\@Work\Perl\monks >perl use strict; use warnings; my $inData = <<INDATA; int abc; .abc(abc); xyzzy int foo; .foo(foo); INDATA open my $in_fh1, '<', \$inData; my $rx_pre = qr{ [ .(] }xms; my $rx_target = qr{ abc }xms; while (my $line = <$in_fh1>) { if ($line =~ m{ $rx_pre $rx_target }xms) { for my $i (1 .. 2) { (my $changed = $line) =~ s{ ($rx_pre $rx_target) }{${1}_$i +}xmsg; print $changed; } } else { print $line; } } ^Z int abc_1; int abc_2; .abc_1(abc_1); .abc_2(abc_2); xyzzy int foo; .foo(foo);
Give a man a fish: <%-{-{-{-<
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
| A reply falls below the community's threshold of quality. You may see it by logging in. |