PDA

View Full Version : Text-transform


Jerome
04-27-2003, 03:40 PM
Hi,

I like to transform the following.

I have:

holiday.257
or
vacation.8976

The result should be:

hol/257
or
vac/8976

In words:

the first 3 letters from the word before the point, than a forward slash, and the complete number after the point.

I tried:

var var1=holiday.257
var1=var1.replace(/(\w{3}).(\w{3})/,'$1/$2');

But my knowledge is to limited!

Thanks,
Jerome

liorean
04-27-2003, 03:46 PM
sString=sString.replace(/^(\w{3})\w+\.(\d+)/,'$1/$2');

Jerome
04-27-2003, 03:52 PM
Fantastic!

By the way, very well written tutorial about regular expressions!

Nice week-end
Jerome

liorean
04-27-2003, 03:56 PM
Well, thank you.

It misses one vital thing which that code used, though: Replace patterns.

I've been thinking of creating a tutorial about string manipulation to make up for that lack, but I've not gotten around to it yet.

Jerome
04-27-2003, 05:48 PM
Studies, he!

The problem with it and working as well, You have no time for important things......

Jerome