Connecting Tech Pros Worldwide Forums | Help | Site Map

cannot get this regex to work!

Geoff Cox
Guest
 
Posts: n/a
#1: Apr 8 '08
Hello,

I have just come back to regex to change a whole lot the x values in
for example to the number/s (this can be 1, 2 or 3 digits) following
the under score character, but cannot get it to work.

So for example,

<fred figure2_312.bmp" Get1(x)>

becomes

<fred figure2_3=312.bmp" Get1(3)>

I have tried

$line =~ /.*_?(\d)\..*?>/;
$line =~ s/x/$1/;

A little help please!

Cheers

Geoff


Jürgen Exner
Guest
 
Posts: n/a
#2: Apr 8 '08

re: cannot get this regex to work!


Geoff Cox <gcox@freeuk.notcomwrote:
Quote:
>Hello,
>
>I have just come back to regex to change a whole lot the x values in
>for example to the number/s (this can be 1, 2 or 3 digits) following
>the under score character, but cannot get it to work.
>
>So for example,
>
><fred figure2_312.bmp" Get1(x)>
>
>becomes
>
><fred figure2_3=312.bmp" Get1(3)>
use warnings; use strict;
$_ = '<fred figure2_312.bmp" Get1(x)>';
s/_(\d)/_=$1/;
my $x = $1;
s/x/$x/;
print;

BTW: this NG has been officially deleted over a decade ago and replaced
with the whole comp.lang.perl.* hierarchie.

jue
Jürgen Exner
Guest
 
Posts: n/a
#3: Jun 27 '08

re: cannot get this regex to work!


Geoff Cox <gcox@freeuk.notcomwrote:
Quote:
>Hello,
>
>I have just come back to regex to change a whole lot the x values in
>for example to the number/s (this can be 1, 2 or 3 digits) following
>the under score character, but cannot get it to work.
>
>So for example,
>
><fred figure2_312.bmp" Get1(x)>
>
>becomes
>
><fred figure2_3=312.bmp" Get1(3)>
use warnings; use strict;
$_ = '<fred figure2_312.bmp" Get1(x)>';
s/_(\d)/_=$1/;
my $x = $1;
s/x/$x/;
print;

BTW: this NG has been officially deleted over a decade ago and replaced
with the whole comp.lang.perl.* hierarchie.

jue
Closed Thread