javascript - How to remove specific strings in a string? -
i have string path = "foo/value/bar/value2", , want extract value parts. because value can null, want removing rest of string.
there no specific pattern, path can anything, example "foo//value/value2" (in case, must remove "foo//" , "/".)
to make things clear, let's write path = foo + "value" + bar + "value".
foo , bar known, not null string values, stored in array array = [foo, bar]
the best solution me separate string path.split(regex), in order have array values, haven't found how split string multiple sources.
var path = "foo/value/bar/value2"; var array = ['foo', 'bar']; var reg = new regexp(array.join("|"),"g"); console.log(path.split(reg));
Comments
Post a Comment