开发者

Regular Expression: interchange words by delimiter

开发者 https://www.devze.com 2023-02-20 17:57 出处:网络
How can I interchange words by delimiter Example: Surname, Name - filename.txt I want this to be come Name Surname - filename.txt

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
0

精彩评论

暂无评论...
验证码 换一张
取 消