I have this code. I am trying to match on .mono-50, where 50 can be any number.
imageUrl = 'http://example.com/media/image.mono-50.png';
imageUrlSplit = imageUrl.split('/.mono-\d+/');
console.log(imageUrlSplit);
This does not match, but does match on my testing tool, regexr.com
I have done many variations on it including the following.
.split('/.mono\-\d+/');
.split('/\.mono\-\d+/');
.split('/.mono-\d+/g');
.split('/.mono\-\d+/g');
.split('/\.mono\-\d+/g');
All of these work in the tool, but none in Javascript. Am I misunderstanding something on how .split() treats Regex?
I have seen this question, but it has not helped me solve this issue.
'/\.mono\-\d+/g'-> the literal string that starts with forward slash contains "mono" and finishes on forward slash and "g"./\.mono\-\d+/gthe regex that matches a pattern that contains a literal dot, followed by "mono" dash and any number of digits.'http://example.com/media/demono-60/image.mono-50.png'would get split incorrectly. @Vld: the global behavior is default withsplit(). A second argument controls that side of splitting.