Rename PDF with regular expressions
Posted: Wed Dec 23, 2015 8:49 am
Hi
I have pdf´s that I need to rename at output. Actually I just need to remove a segment within the name.
Usually the files are named with this syntax:
S60_15w46_V1_DEde.pdf
But there can be variations in the first segment:
XC60_15w46_V1_DEde.pdf
V60CC_15w46_V1_DEde.pdf
(There can alos be variations in the digits and country code, but not in length)
And I need to remove the ”_V1_” from the filename. And replace it with just a ”_". Or just remove "V1_".
I know how to match the whole name with regular expressions.
([A-Za-z0-9]*)_([0-9][0-9])w([0-9][0-9])_V([0-9])_([A-Z][A-Z])([a-z][a-z])\.(pdf|PDF)
And the first segment:
([A-Za-z0-9]*)_([0-9][0-9])w([0-9][0-9])
V60CC_15w46_V1_DEde.pdf
And also the last segment:
(([A-Z][A-Z])([a-z][a-z])\.(pdf|PDF))
XC60_15w46_V1_DEde.pdf
But I can not figure out how to use the two segments in the output name.
Any suggestions?
Thanks.
I have pdf´s that I need to rename at output. Actually I just need to remove a segment within the name.
Usually the files are named with this syntax:
S60_15w46_V1_DEde.pdf
But there can be variations in the first segment:
XC60_15w46_V1_DEde.pdf
V60CC_15w46_V1_DEde.pdf
(There can alos be variations in the digits and country code, but not in length)
And I need to remove the ”_V1_” from the filename. And replace it with just a ”_". Or just remove "V1_".
I know how to match the whole name with regular expressions.
([A-Za-z0-9]*)_([0-9][0-9])w([0-9][0-9])_V([0-9])_([A-Z][A-Z])([a-z][a-z])\.(pdf|PDF)
And the first segment:
([A-Za-z0-9]*)_([0-9][0-9])w([0-9][0-9])
V60CC_15w46_V1_DEde.pdf
And also the last segment:
(([A-Z][A-Z])([a-z][a-z])\.(pdf|PDF))
XC60_15w46_V1_DEde.pdf
But I can not figure out how to use the two segments in the output name.
Any suggestions?
Thanks.