Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > How replace ing2004 to ing-2004 ? please help

Reply
Thread Tools

How replace ing2004 to ing-2004 ? please help

 
 
Franšois
Guest
Posts: n/a
 
      10-06-2003
I want to replace an expression abc1234 to abc-1234 how can i do
I 've tried

s/......./$1$2$3-$4$5$6$7/ but it dont work.

Please help ?

Thanks a lot


 
Reply With Quote
 
 
 
 
Andreas Kahari
Guest
Posts: n/a
 
      10-06-2003
In article <blrqe4$i6a$(E-Mail Removed)>, Franšois wrote:
> I want to replace an expression abc1234 to abc-1234 how can i do
> I 've tried
>
> s/......./$1$2$3-$4$5$6$7/ but it dont work.



s/(\w{3})(\d{4})/$1-$2/


--
Andreas Kńhńri
 
Reply With Quote
 
 
 
 
Josef M÷llers
Guest
Posts: n/a
 
      10-06-2003
Bernard El-Hagin wrote:
>
> "Franšois" <(E-Mail Removed)> wrote in news:blrqe4$i6a$1
> @s1.read.news.oleane.net:
>
> > I want to replace an expression abc1234 to abc-1234 how can i do
> > I 've tried
> >
> > s/......./$1$2$3-$4$5$6$7/ but it dont work.
> >
> > Please help ?

>
> s/(\D+)(\d+)/$1-$2/


TMTOWTDI

I'd use
s/(\D{3})(\d{4})/$1-$2/

It's a little more robust when the abc1234 is not the only thing on a
line.

Josef
--
Josef M÷llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
 
Reply With Quote
 
Helgi Briem
Guest
Posts: n/a
 
      10-06-2003
On Mon, 6 Oct 2003 15:23:44 +0200, "Franšois" <(E-Mail Removed)> wrote:

>I want to replace an expression abc1234 to abc-1234 how can i do
>I 've tried
>
>s/......./$1$2$3-$4$5$6$7/ but it dont work.


I presume the format is originally
3 letters 4 numbers?

If so:

s/(^[a-z]{3})(\d{4})$/$1-$2/;

 
Reply With Quote
 
Josef M÷llers
Guest
Posts: n/a
 
      10-06-2003
Bernard El-Hagin wrote:
>
> Josef M÷llers <(E-Mail Removed)> wrote in
> news:(E-Mail Removed):
>
> > Bernard El-Hagin wrote:
> >>

> >
> >> "Franšois" <(E-Mail Removed)> wrote in news:blrqe4$i6a$1
> >> @s1.read.news.oleane.net:
> >>

> >
> >> > I want to replace an expression abc1234 to abc-1234 how can i do
> >> > I 've tried
> >> >
> >> > s/......./$1$2$3-$4$5$6$7/ but it dont work.
> >> >
> >> > Please help ?
> >>

> >
> >> s/(\D+)(\d+)/$1-$2/

> >
> > TMTOWTDI
> >
> > I'd use
> > s/(\D{3})(\d{4})/$1-$2/
> >
> > It's a little more robust when the abc1234 is not the only thing on a
> > line.

>
> s/abc1234/abc-1234/ is even more robust.


Why didn't I think of that B-{)))

> That's the problem with general specifications of problems.


Yes, you're right.
--
Josef M÷llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
 
Reply With Quote
 
Franšois
Guest
Posts: n/a
 
      10-06-2003
thanks that work

"Helgi Briem" <(E-Mail Removed)> a Úcrit dans le message de
news:(E-Mail Removed)...
> On Mon, 6 Oct 2003 15:23:44 +0200, "Franšois" <(E-Mail Removed)> wrote:
>
> >I want to replace an expression abc1234 to abc-1234 how can i do
> >I 've tried
> >
> >s/......./$1$2$3-$4$5$6$7/ but it dont work.

>
> I presume the format is originally
> 3 letters 4 numbers?
>
> If so:
>
> s/(^[a-z]{3})(\d{4})$/$1-$2/;
>



 
Reply With Quote
 
Eric J. Roode
Guest
Posts: n/a
 
      10-07-2003
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

"Franšois" <(E-Mail Removed)> wrote in news:blrqe4$i6a$1
@s1.read.news.oleane.net:

> I want to replace an expression abc1234 to abc-1234 how can i do
> I 've tried
>
> s/......./$1$2$3-$4$5$6$7/ but it dont work.
>
> Please help ?


In order for $1 (etc) to work, the left-hand side of the expression needs
to have parentheses in it. For example:

s/(.)(.)(.)(.)(.)(.)(.)/$1$2$3-$4$5$6$7/

should do the trick for you.

The following:

s/(...)(....)/$1-$2/

does the same thing (effectively), but is shorter and easier to write.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP4IFtWPeouIeTNHoEQKECgCgwuDkBaMvCKw/oyw2eo7TCgcd1W4AoM2U
/nwmtz5QEnAVUVQjogosdg0F
=Du8q
-----END PGP SIGNATURE-----
 
Reply With Quote
 
Randal L. Schwartz
Guest
Posts: n/a
 
      10-07-2003
>>>>> "Franšois" == Franšois <(E-Mail Removed)> writes:

Franšois> I want to replace an expression abc1234 to abc-1234 how can i do
Franšois> I 've tried

Franšois> s/......./$1$2$3-$4$5$6$7/ but it dont work.

s/abc1234/abc-1234/ would do it, as would $_ = "abc-1234", but since
you've given only one example and no rules, it's hard to generalize
that.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<(E-Mail Removed)> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
pyrex functions to replace a method (Re: replace a method in class:how?) Brian Blais Python 1 06-27-2006 12:13 PM
help with string replace - for doing selective replace Prasad S Javascript 2 08-27-2004 03:22 PM
HELP! HELP! PLEASE, PLEASE, PLEASE tpg comcntr Computer Support 11 02-15-2004 06:22 PM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments