Вопрос

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(/[/\\]/);
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top