我正在尝试编写一个正则表达式来从单词的开头删除空格,而不是在单词之后,并且在单词之后只删除一个空格。
使用正则表达式:
var re = new RegExp(/^([a-zA-Z0-9]+\s?)*$/);
测试示例:
1) wordX[space] - Should be allowed
2) [space] - Should not be allowed
3) WrodX[space][space]wordX - Should be allowed
4) WrodX[space][space][space]wordX - Should be allowed
5) WrodX[space][space][space][space] - Should be not be allowed
6) WrodX[space][space] - Allowed with only one space the moment another space is entered **should not be allowed**