in reply to find a substring using regex and then replace it
There are 2 problems there: you are using bge1 as a bareword and you are escaping the dollars in the regex thus preventing them from doing what you want. Here's the working version:
#!/usr/bin/env perl use strict; use warnings; my $Interface = 'bge1'; $Interface =~ s/[0-9]$/:$&/; print $Interface . "\n";
which outputs "bge:1".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: find a substring using regex and then replace it
by johngg (Canon) on May 02, 2016 at 16:08 UTC |