What is the reason for this?
Illustration 1
re = new RegExp('\\$\\[(.+)\\]\\(([S,M,L]),([L,C,R])\\)', 'g')
'$[sds](S,L)'.replace(re, function(a,b,c,d) {
console.log(a,b,c,d); return 'test';
})
yet this fails to work
Illustration 2
re = new RegExp('\\$\\[(\S+)\\]\\(([S,M,L]),([L,C,R])\\)', 'g')
'$[sds](S,L)'.replace(re, function(a,b,c,d) {
console.log(a,b,c,d); return 'test';
})
The key difference between the two is that Illustration 1 includes .+
, whereas in illustration 2 it's \S+
.
The expectation is for \S+
to identify the sds
within the brackets, operating similarly to .+