If you're just going to split, there's no need to replace beforehand then split. You can pass the regex to the split
function directly. Like this:
var parts = mPath.split(/[/\\]/);
質問
I want to split a path containing forward and/or backward slashes into parts using Google Apps script. I prefer doing this by using a single RegExp instead of writing much code.
so code should look like
var myPath = "<something>"; // i.e. \first\second/third\filename.extension
var parts = myPath.replace(<a regular expression>).split('/');
Allthough I searched SO, I didn't find a solution.
What should <a regular expression>
be?
解決
If you're just going to split, there's no need to replace beforehand then split. You can pass the regex to the split
function directly. Like this:
var parts = mPath.split(/[/\\]/);