-6

I have a text file that contains roughly a thousand file names that I need to change slightly. Each file name is a date and time formatted like:

2013-05-01 120125.jpg

I need to convert all of them to:

2013-05-01 12.01.25.jpg

I'm assuming this would be fairly trivial with regular expressions, but I am always confounded when I try to do anything with them! Help is appreciated!

mickmackusa
  • 33,121
  • 11
  • 58
  • 86
zip_000
  • 1
  • 2
  • 5
    What have you tried? Show your work. SO is not a code writing service, you have to do your own work and we can help you fix the problems you encounter. – Soviut Jul 09 '17 at 21:50
  • What language/environment will be running this regex? – mickmackusa Jul 09 '17 at 22:45
  • I'll most likely be running the regex in nano. What I'm trying to do is to bulk change file names using renameutils. This opens a nano file with all the filenames in the folder. – zip_000 Jul 09 '17 at 22:50

3 Answers3

1

You want to use a replace technique (in whatever language/environment you are using) on your substrings by capturing like this:

(\d{2})(\d{2})(\d{2})

*note the curly brackets are for improved efficiency.

And replace with:

$1.$2.$3

Here is a demo link.

Here is a SO page discussing the execution of replacements on nano.

mickmackusa
  • 33,121
  • 11
  • 58
  • 86
0

Use capture groups to match the digits, and copy them to the replacement.

Replace: (\d\d)(\d\d)(\d\d)\.jpg

With: $1.$2.$3.jpg

$1, $2, $3 copy the parts of the original string that each capture group matched.

Barmar
  • 596,455
  • 48
  • 393
  • 495
-1

As mentioned by Soviut, SO is for help and not doing the work for you. That being said:

If you want to do something with Regular Expressions you're best going to the Rubular website which allows you to create your regex whilst seeing exactly what result you're getting.

Rubular

Paul Stringer
  • 90
  • 2
  • 10
  • 1
    Something tells me this "answer" shouldn't be here, but in the comment section instead... oh – Mateus Jul 09 '17 at 21:57
  • 1
    Thanks, I'll read up. I wasn't trying to avoid learning it... well maybe a little... I just always feel very overwhelmed with regex. This isn't homework help or anything, just trying to merge some files. – zip_000 Jul 09 '17 at 22:02