Rearrange file name parts
Greetings - using this forum, I've been able to answer a lot of my questions, but I'm stumped on this one. I have a bunch of file names in the following format:
word1 word2 word3-yyyy-mm-dd.ext
I would like to move the yyyy-mm-dd in between word2 and word3, adding "--" so that it looks like this:
word1 word2 yyyy-mm-dd--word3.ext
I've played around with the \w expression, but can't seem to get it right. Can someone kindly help?
Thanks,
Dataguy
word1 word2 word3-yyyy-mm-dd.ext
I would like to move the yyyy-mm-dd in between word2 and word3, adding "--" so that it looks like this:
word1 word2 yyyy-mm-dd--word3.ext
I've played around with the \w expression, but can't seem to get it right. Can someone kindly help?
Thanks,
Dataguy
Reply to #1:
Hi Dataguy,
Based on the limited example there are many ways to do what you want. Here are a few. They all require using one replace method with regular expressions checked.
(1)
Replace: (<word:1>) (<word:2>) (<word:3>)-(.*)
Replace with: $1 $2 $4--$3
(2)
R: <word:1> <word:2> <word:3>-(.*)
Rw: <word:1> <word:2> $1--<word:3>
(3)
R: (\w+) (\w+) (\w+)-(\d{4}-\d{2}-\d{2})
Rw: $1 $2 $4--$3
(4)
R: ([^ ]+) ([^ ]+) ([^-]+)-(.*)
Rw: $1 $2 $4--$3
(No spaces before or after the expressions, just inside them)
There's one more way I thought of, that doesn't use regular expressions:
R: <word:3>-<word:4>-<word:5>-<word:6>
Rw: <word:4>-<word:5>-<word:6>--<word:3>
Just in case you are regex-shy... :)
Let us know how these work out for you.
Best
DF
Hi Dataguy,
Based on the limited example there are many ways to do what you want. Here are a few. They all require using one replace method with regular expressions checked.
(1)
Replace: (<word:1>) (<word:2>) (<word:3>)-(.*)
Replace with: $1 $2 $4--$3
(2)
R: <word:1> <word:2> <word:3>-(.*)
Rw: <word:1> <word:2> $1--<word:3>
(3)
R: (\w+) (\w+) (\w+)-(\d{4}-\d{2}-\d{2})
Rw: $1 $2 $4--$3
(4)
R: ([^ ]+) ([^ ]+) ([^-]+)-(.*)
Rw: $1 $2 $4--$3
(No spaces before or after the expressions, just inside them)
There's one more way I thought of, that doesn't use regular expressions:
R: <word:3>-<word:4>-<word:5>-<word:6>
Rw: <word:4>-<word:5>-<word:6>--<word:3>
Just in case you are regex-shy... :)
Let us know how these work out for you.
Best
DF
Reply to #2:
Thank you very much, DF! All these produced similar results, but #4 worked the best for slight variations in my input file name.
Thanks again,
Dataguy
Thank you very much, DF! All these produced similar results, but #4 worked the best for slight variations in my input file name.
Thanks again,
Dataguy
Reply to #3:
Hi DG,
Glad to help. I included several ways to slice the pie because usually people don't realize that those "slight variations" can defeat some otherwise effective strategies. #4 bases its division of "words" on the spaces, ignoring other characters. Once the "words" are captured it then captures the date string by assuming that everything following the dash character is the date.
Did you try the non-regex method? It took me some time to figure that one out, it wasn't intuitively obvious to me like the others. Anyway, have a great day my friend!
DF
Hi DG,
Glad to help. I included several ways to slice the pie because usually people don't realize that those "slight variations" can defeat some otherwise effective strategies. #4 bases its division of "words" on the spaces, ignoring other characters. Once the "words" are captured it then captures the date string by assuming that everything following the dash character is the date.
Did you try the non-regex method? It took me some time to figure that one out, it wasn't intuitively obvious to me like the others. Anyway, have a great day my friend!
DF