Adding 0 before variable numbers

A swapping-ground for Regular Expression syntax

Adding 0 before variable numbers

Postby Dreeg » Sat Jan 17, 2015 3:43 pm

Hi,

I have more files with this formats, where 'Word word' is ever the same and 'Z' is a variable number:
"Word word 01x Z - varaible_word (possible other words).extension"
"Word word 01x ZZ - varaible_word (possible other words).extension"
"Word word 01x ZZZ - varaible_word (possible other words).extension"

I want add 0 and 00 in ZZ and Z cases.

How?

I tried these expressions but don't work :\

Match:(.+)( \d{1,2} )(.+)
Replace: \1\02\3

How I can "add" some digit character with regular expression?
Dreeg
 
Posts: 2
Joined: Sat Jan 17, 2015 3:29 pm

Re: Adding 0 before variable numbers

Postby TheRegExpMaster » Sun Jan 18, 2015 8:44 pm

Hi Dreeg, could you please give a few examples of files you want to rename and the result ? Thanks.
TheRegExpMaster
 
Posts: 25
Joined: Wed Nov 05, 2014 8:45 pm

Add 0 zeros padded to wanted length

Postby Stefan » Mon Jan 19, 2015 8:37 am

One possible way would be:


FROM
Word word 01x Z - varaible_word (possible other words).txt
Word word 01x ZZ - varaible_word (possible other words).txt
Word word 01x ZZZ - varaible_word (possible other words).txt

TO:
Word word 01x 00Z - varaible_word (possible other words).txt
Word word 01x 0ZZ - varaible_word (possible other words).txt
Word word 01x ZZZ - varaible_word (possible other words).txt

USE 1.):
RegEx(1)
Match:(.+x )(.+)( - .+)
Repla:\100\2\3

[RENAME]

to get:
Word word 01x 00Z - varaible_word (possible other words).txt
Word word 01x 00ZZ - varaible_word (possible other words).txt
Word word 01x 00ZZZ - varaible_word (possible other words).txt


Explanantion:
Match 'anything till x + space' as \1,
then anything as \2
till 'space hyphen space and the rest' as \3.
Add as many zeros as wanted.

- - -

Then USE 2.):
RegEx(1)
Match:(.+x )(.+)(...)( - .+)
Repla:\1\3\4

[RENAME]


to get the wanted:
Word word 01x 00Z - varaible_word (possible other words).txt
Word word 01x 0ZZ - varaible_word (possible other words).txt
Word word 01x ZZZ - varaible_word (possible other words).txt

Explanantion:
Match 'anything till x + space' as \1,
then anything as \2 till
the last three signs from that anything as \3
till 'space hyphen space and the rest' as \4.


Done.

 
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU

Re: Adding 0 before variable numbers

Postby Dreeg » Sat Jan 24, 2015 8:07 pm

Thank you guys!
I resolved with the solution 1!! :D
Dreeg
 
Posts: 2
Joined: Sat Jan 17, 2015 3:29 pm


Return to Regular Expressions