How replace ing2004 to ing-2004 ? please help

F

François

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
 
A

Andreas Kahari

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/
 
J

Josef Möllers

Bernard said:
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
 
H

Helgi Briem

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/;
 
F

François

thanks that work

Helgi Briem said:
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/;
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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-----
 
R

Randal L. Schwartz

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top