I have this code:
var r = /(?:^s*([^s]*)s*)(?:,s*([^s]*)s*){0,}$/
var s = " a , b , c "
var m = s.match(r)
m => [" a , b , c ", "a", "c"]
Looks like the whole string has been matched, but where has "b"
gone? I would rather expect to get:
[" a , b , c ", "a", "b", "c"]
so that I can do m.shift()
with a result like s.split(',')
but also with whitespaces removed.
Do I have a mistake in the regexp or do I misunderstand String.prototype.match
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…