How can I use GPRename's regex feature to reinsert the matched-group into the 'replace'?
Posted
by
David Thomas
on Ask Ubuntu
See other posts from Ask Ubuntu
or by David Thomas
Published on 2012-09-04T14:06:20Z
Indexed on
2012/09/04
15:53 UTC
Read the original article
Hit count: 846
I've been using GPRename to batch-rename files; this is rather more efficient than individually correcting each file, but still seems to be less efficient than it might be, primarily because either I don't understand the regex syntax used, or because the regex implementation is incomplete1
Given a list of files of the following syntax:
(01) - title of file1.avi
(02) - title of file2.avi
(03) - title of file3.avi
I attempted to use the 'replace' (with the regex option selected, the case-sensitive option deselected):
(\(\d{2}\))
The preview then shows (given that I've specified no 'replace with' option as yet):
title of file1.avi
title of file2.avi
title of file3.avi
Which is great, clearly the regex is identifying the correct group (the (01)
). Now, what I was hoping to do (using the JavaScript syntax) in the 'replace with' option is use:
$1
(I also tried using '$1'
, \1
and '\1'
)
This was just to check that I could access the matched group, and it seems I can't, the matched group is, as I suppose might be expected, replaced with the literal replacement string.
So, my question: is it possible to match a particular group of characters, in this case the numbers within the brackets, and then insert those into the replacement string? Therefore:
(01) title of file1.avi
(02) title of file2.avi
(03) title of file3.avi
Becomes:
01 title of file1.avi
02 title of file2.avi
03 title of file3.avi
- I absolutely suspect the former, personally.
© Ask Ubuntu or respective owner