I am trying get directory name with backslash, but I am getting this DirectoryFolder. Can't figure out how to match backslah \ as well.
DirPath = "Directory\Folder"
val = DirPath.match(/(\w+)/)[1];
The result I want is this
Directory\Folder
I am trying get directory name with backslash, but I am getting this DirectoryFolder. Can't figure out how to match backslah \ as well.
DirPath = "Directory\Folder"
val = DirPath.match(/(\w+)/)[1];
The result I want is this
Directory\Folder
If I understand your question correctly, you need to know how to match a backslash, correct?
If that is the case, you can escape your backslash
The final regex would look like /(\w|\\)+/
Can you use ES6? If so you can use the String.raw()
static method:
var DirPath = String.raw`Directory\Folder`;
var re = /[\w\\]+/;
document.body.textContent = DirPath.match(re);