Inserting Leading Zeros into a CSV file using Regular Expres

General discussions about Advanced Find and Replace
Post Reply
joekoko
Posts: 1
Joined: Mon Jan 31, 2005 5:32 pm

Inserting Leading Zeros into a CSV file using Regular Expres

Post by joekoko » Mon Jan 31, 2005 5:32 pm

Hi all,

I love this program as it has been very helpful with my work.

Can anyone share with me on how to use AFR to do the following:

Original file:

"2002",20041206,36,1,"2","03111684254", 30,"99"," ","8010","9058"," "
"2002",20041206,37,1,"2","531780103P0", 24,"99"," ","8010","9058"," "

I need to replace the bolded regions, which is a counter with a counter that has leading zeros. This field should have 6 numbers altogether. Which means that my result file should be:

"2002",20041206,000036,1,"2","03111684254", 30,"99"," ","8010","9058"," "
"2002",20041206,000037,1,"2","531780103P0", 24,"99"," ","8010","9058"," "

Thanks and I appreciate any help here.

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jan 31, 2005 5:32 pm

Hi,

Assuming that on 3rd place you have only 2 digits now and you want to
add 4 leading zeros, the final r.e. will be:

search for:
^(.+),(.+),(.+),

replace with:
$1,$2,0000$3,

I verified it works.

Note: Modifier S should be OFF.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Guest

Thanks. How about the following cases then?

Post by Guest » Mon Jan 31, 2005 5:32 pm

Hi Roman,

Thanks for answering my question.

I think I may not have communicated the entire scenario clearly. I need to have leading zeros for the third place variable (i.e. the counter) and this counter runs from 000001 ~ 999999. How do I include a limiter to say that we will fill up the field with leading zeroes as long as there are less than 6 chars in the field.

i.e.

1
2
36
492
4445
52341

000001
000002
000036
000492
004445
052341

I'd appreciate if you could spare some time to think on this query.

Thanks again.

Abacre
Site Admin
Posts: 1198
Joined: Mon Jan 31, 2005 5:32 pm
Contact:

Post by Abacre » Mon Jan 31, 2005 5:32 pm

I thought about your scenario.

So the quick solution is to put 5 pairs into Batch grid:

Search for:
^(.+),(.+),(\d{1}),
Replace with:
$1,$2,00000$3,

Search for:
^(.+),(.+),(\d{2}),
Replace with:
$1,$2,0000$3,

Search for:
^(.+),(.+),(\d{3}),
Replace with:
$1,$2,000$3,

Search for:
^(.+),(.+),(\d{4}),
Replace with:
$1,$2,00$3,

Search for:
^(.+),(.+),(\d{5}),
Replace with:
$1,$2,0$3,


So \d means any digit
and {} mentions number of times.
Kind regards,
Abacre Limited
http://www.abacre.com
support@abacre.com

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests