On Thu, Jan 3, 2013 at 3:37 AM, Hamann, T.D. thomas.ham...@naturalis.nlwrote:
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
On 01/07/2013 12:41 PM, Andy Bach wrote:
On Thu, Jan 3, 2013 at 3:37 AM, Hamann, T.D. thomas.ham...@naturalis.nlwrote:
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,
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:
i994
where I want to replace
Hi,
why not use tr?
$str =~ tr/io/10/;
Brs
想念你的每一天
- 原邮件 -
发件人: Hamann, T.D. thomas.ham...@naturalis.nl
收件人: beginners@perl.org beginners@perl.org
抄送:
发送日期: 2013年1月2日, 星期三, 10:34 下午
主题: Substituting letters for numbers
Hello,
Given a string:
i994
where I want to replace
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'
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
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:
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/
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 I want to replace the 'i' by a '1' and the 'o' by a '0' (zero), the
following regex fails:
Hi Thomas,
On Wed, 2 Jan 2013 14:34:07 +
Hamann, T.D. thomas.ham...@naturalis.nl 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
10 matches
Mail list logo