On 01/07/2013 12:41 PM, Andy Bach wrote:
On Thu, Jan 3, 2013 at 3:37 AM, Hamann, T.D. wrote:
and then using a second regular expression to remove the space, but
that somehow seems silly. Surely there is a quicker way to do this?
s/(i)(\d\d)(o)/1${2}0/;
One route, esp. if there might be mor
On Thu, Jan 3, 2013 at 3:37 AM, Hamann, T.D. wrote:
> > and then using a second regular expression to remove the space, but
> > that somehow seems silly. Surely there is a quicker way to do this?
>
> s/(i)(\d\d)(o)/1${2}0/;
>
One route, esp. if there might be more letter<->number pairs (like "lee
to change vowels into numbers ;).
Thomas
-Original Message-
From: John W. Krahn [mailto:jwkr...@shaw.ca]
Sent: Thursday, January 03, 2013 9:19 AM
To: Perl Beginners
Subject: Re: Substituting letters for numbers
Hamann, T.D. wrote:
> Hello,
Hello,
> Given a string:
>
> i9
On 2013-01-03 17:42, Andy Bach wrote:
s/(i)([0-9]{2})(o)/1${2}0/;
But why capture and don't use?
s/i([0-9]{2})o/1${1}0/;
--
Ruud
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/
> s/(i)(\d\d)(o)/1$20/;
You don't need to capture the "i" or "o"
s/i(\d+)o/1${1}0/
If there were more i or o's, 2 subs
s/i/1/g
s/o/0/g
The "g" globally replacing all the matches. There's probably a tricky way to
do that in one but.
> Since you are capturing 3 groups:
s/(i)([0-9]{2})(o)/
On 2013-01-02 15:34, Hamann, T.D. wrote:
[...] given a string:
i99o
where I want to replace the 'i' by a '1' and the 'o' by a '0' (zero), the
following regex fails:
s/(i)(\d\d)(o)/1$20/;
Since you are capturing 3 groups:
s/(i)([0-9]{2})(o)/$1$2$3/;
for the obvious reason that perl l
Hamann, T.D. wrote:
Hello,
Hello,
Given a string:
i994
where I want to replace the 'i' by a '1' the following regex
succesfully replaces the letter by a number:
s/(i)(\d\d\d)/1$2/;
tr/i/1/;
However, given a string:
i99o
where I want to replace the 'i' by a '1' and the 'o' by a '0'
Hi Thomas,
On Wed, 2 Jan 2013 14:34:07 +
"Hamann, T.D." wrote:
> Hello,
>
> Given a string:
>
> i994
>
> where I want to replace the 'i' by a '1' the following regex succesfully
> replaces the letter by a number:
>
> s/(i)(\d\d\d)/1$2/;
>
> However, given a string:
>
> i99o
>
> where