Regular Expression: interchange words by delimiter
How can I interchange words by delimiter
Example:
Surname, Name - filename.txt
I want this to be come
Name Surname - filename.txt
I have file renamer which can 开发者_如何学运维rename file with regular expressions (A better rename in mac, and better file renamer on windows)
is it possible at all?
Matching expression:
/^(.+), (.+) - (.+)$/
Replacement pattern:
$2 $1 - $3
Something along these lines should work, but this really depends on the capabilities and semantics of your regex engine and your specific input. No idea what Better Renamer allows you to do.
$ echo "Surname, Name - filename.txt" | ruby -e 'print gets.gsub(/(\w+),\s+(\w+)(\s+-\s+\w+)/, "\\2 \\1 \\3")'
Name Surname - filename.txt
精彩评论