Insert a zero before a single digit

Help with writing and playing macros

Insert a zero before a single digit

Postby spottiswoad » Fri Aug 19, 2011 10:12 pm

Hiya folks,
Is there a macro available that would insert a zero before all single digits? 1 becomes 01, 9 becomes 09. I've searched these forums for a clue but haven't read anything that would pertain to this. Much help needed.
spottiswoad
Newbie
 
Posts: 4
Joined: Sun Jul 24, 2011 10:43 am

Re: Insert a zero before a single digit

Postby Mofi » Sat Aug 20, 2011 2:46 pm

There is no real need for a macro because this can be done by running a tagged regular expression replace all with any of the 3 regexp engines and using additionally Match Whole Word Only option. This single replace all recorded to a macro:

Using the UltraEdit engine:
Top
UnixReOff
Find RegExp MatchWord "^([0-9]^)"
Replace All "0^1"


Using the Unix engine:
Top
UnixReOn
Find RegExp MatchWord "([0-9])"
Replace All "0\1"


Using the Perl engine:
Top
PerlReOn
Find RegExp MatchWord "([0-9])"
Replace All "0\1"


With the Perl engine there would be also other possibilities without MatchWord, but there is no reason to make something more difficult than really necessary.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Insert a zero before a single digit

Postby spottiswoad » Sat Aug 20, 2011 8:39 pm

Mofi,

Took awhile to respond but had to figure out what a tagged regular expression was. UE website has an example and the UE program help files has info there, too. Would have still been confused if not for your example. So much to learn about this great program and the concept behind coding and understanding it.

Thank you for your teachings.
spottiswoad
Newbie
 
Posts: 4
Joined: Sun Jul 24, 2011 10:43 am


Return to Macros