我想写一个正则表达式,只删除单词开头的空格,不删除单词后面的空格,并且在单词后只保留一个空格。
使用的RegExp:
var re = new RegExp(/^([a-zA-Z0-9]+\s?)*$/);
测试例子:
1) test[space]ing - Should be allowed
2) testing - Should be allowed
3) [space]testing - Should not be allowed
4) testing[space] - Should be allowed but have to trim it
5) testing[space][space] - should be allowed but have to trim it
只允许一个空格,这可能吗?
a b c
吗? - Steely Wing