I am trying to write a regular expression for JavaScript.
I have file names with folders and I need to consolidate them from the git changes. e.g. Input:
"9 1 {Folder_Old => Folder}/FileTest1.cs"
"0 9 File{a => t}est2.cs"
"- - F{a => i}leT{b => e}st.d{c => l}l"
"9 1 {test/File.cs => test/File1.cs}"
Expected Output per line:
"9 1 Folder/FileTest1.cs"
"0 9 Filetest2.cs"
"- - FileTest.dll"
"9 1 test/File1.cs"
Here is what I have tried so far:
var myentry = '9 9 {Folder_Old => Folder}/FileTest1.cs'
//find { A => B }
//replace { A => B } with B
let result = myentry.match(/{.+=>.+}/g);
console.log(result[0]) //"{Folder_Old => Folder}"
result[0] = result[0].replace('{', '')
result[0] = result[0].replace('}', '')
console.log(result[0]) //"Folder_Old => Folder"
var me = result[0].split(' ')
console.log(me) //["Folder_Old", "=>", "Folder"]
var he = myentry.replace(/{.+=>.+}/g, me[2])
console.log(he) //"9 9 Folder/FileTest1.cs"
How can I change my algorithm to cover all the cases?