1

I need to create a regular expression which transforms a path to a cloud solution.

\\test.local\testb\test-prozesse\project_prozess\1_Implementierung\2__Datenmigration\1_prozesstest\5_Dokumentation\Dateiname.docx

to this:

Test-USER>2__Datenmigration>1_prozesstest>5_Dokumentation>Dateiname.docx

The first part is to be replaced with the "Test-USER" and the slashes should be replaced with the >.

I only managed to delete the first part with this:

\\\\[a-zA-Z._]+\\[a-zA-Z._]+\\[a-zA-Z._-]+\\[0-9a-zA-Z._-]+\\[0-9a-zA-Z._-]+\\

I use the open source project pathcopycopy and there you have only one line to insert your regular expression

LaYn
  • 11
  • 2

1 Answers1

-1

const str = '\\\\test.local\\testb\\test-prozesse\\project_prozess\\1_Implementierung\\2__Datenmigration\\1_prozesstest\\5_Dokumentation\\Dateiname.docx';


const result = str.replace(/^(\\+[^\\]*)(\\+[^\\]*)(\\+[^\\]*)\\?([\w\W]*)$/, function ($0, $1, $2, $3, $4) {   return $4.split('\\').join('>');
})


console.log('result= ', result);
Steve Tomlin
  • 3,391
  • 3
  • 31
  • 63