JSFiddle - React, Tailwind, and code Playground JavaScript var v = 'C:/fakepath/text.txt'; alert(v.replace(/.*[\\\/]/g,''));