Reputation: 623
I am looking for an easy way using regex to change the format of a string. this is what I have
POL-CAD-OPT-1-15-31Oct14
INS-DOT-OPT-5-7-13Jun14
BOL-GUP-OPT-5-5-28Oct14
this is what it should be
POL-CAD-OPT-01-15-31Oct14
INS-DOT-OPT-05-07-13Jun14
BOL-GUP-OPT-05-05-28Oct14
right now I am using old split feature to construct the string using if length = 1 then add 0.
is there anything I can do with RegEx ?
Upvotes: 2
Views: 130
Reputation: 7948
Edit per comment below :
use this pattern
-(\d)(?=-)
and replace with -0$1
Demo
- '-'
( group and capture to \1:
\d digits (0-9)
) end of \1
(?= look ahead to see if there is:
- '-'
) end of look-ahead
Upvotes: 3