3

So I have long list of files that I'm trying to use regex to rename but, it looks like it does not take standard regular expressions. I’m sure I’m just doing this incorrectly.

After entering dired and C-x C-q to make the files writable. I do M-% or query-replace-regexp to start the regex file rename but it does not work.

I tried doing a query replace for .eps\d.* to match everything then a replace with .mkv with no luck. What is the proper way to complete this task?

Starting File list example:

Show.S03E01.eps3.0.modifer322344.mkv
Show.S03E02.eps3.1.someihtng.else.mkv
Show.S03E03.eps3.2.lega.matters.mkv
Show.S03E04.eps3.3.data.par2.mkv

Finished File list example:

Show.S03E01.mkv
Show.S03E02.mkv
Show.S03E03.mkv
Show.S03E04.mkv
2
  • It's not clear what the names in the example list represent: the initial names, the final names? Could you edit the question to provide a list of initial names and the corresponding list of desired final names?
    – NickD
    Jan 29, 2020 at 3:29
  • I'm just trying to figure out how to properly use regular expression with dired. I see that it does not like backslash as an escape like \d for digits. Jan 29, 2020 at 3:36

1 Answer 1

3

I do M-% to start the regex file rename but it does not work.

M-% runs the command query-replace

C-M-% runs the command query-replace-regexp


I see that it does not like backslash as an escape like \d for digits.

Indeed; a digit is matched with [0-9] or [[:digit:]]

You can read about the regular expression syntax supported by Emacs with:

  • C-hig (emacs)Search
  • C-hig (elisp)Regular Expressions

I tried doing a query replace for .eps\d.* to match everything then a replace with .mkv

Search for \.eps[0-9].*
or perhaps \.eps[0-9].*\.mkv

2
  • I tried the C-M-% and the following .eps\d.* gave me "Replaced 0 occurrences" any suggestions to make this work? Jan 29, 2020 at 2:09
  • Answer updated.
    – phils
    Jan 29, 2020 at 4:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.