views:

126

answers:

2

Hi guys, i'm really not good with regular expressions and i need one to transform "1.2.3" to "1.02.03" in a way that first part stays always as it was and second and third one will transform 2 to 02, 7 to 07 and so on but if there is 10, 15, 17 and so on it will leave it as it is. I want to use it in msbuild.

samples:

2.5.7  -> 2.05.07
2.10.9 -> 2.10.09
1.7.18 -> 1.07.18

Thanks.

A: 
/\.\([1-9]\)[([.$])]/.0\1\2/g

Starts with a dot, one number, dot or line end to dot zero number endsym.

Dutow
+4  A: 
/\.(\d)(?=\D|$)/g  =>  .0$1

Works with any number of dots :)

Edit: when look-ahead isn't supported but word boundaries are, you can use

/\.(\d)\b/g  =>  .0$1

... or just because it's simpler :)

streetpc
+0 But with a limited number of regex engines :)
soulmerge
True, added another using word boundaries
streetpc