我正在尝试编写一个正则表达式来从单词的开头删除空格,而不是在单词之后,并且在单词之后只删除一个空格。
这是我尝试过的正则表达式:
var re = new RegExp(/^([a-zA-Z0-9]+\s?)*$/);
Output -
re.test("")
true - required false
re.test(" ")
false
re.test(" word")
false - required word - true
re.test(" word ")
false - required word - true
re.test("word ")
true
re.test("word ")
false - - required word(with single space ) - true
经验:
看,我必须向后端发送请求,如果
1) key term is ""(blank) no need to send the request.
2) If key is " string" need to send the request.
3) If user enter something like this "string string" need to send the request.
4) if user enter "string " need to send the request.
5) if user enter string with a space need to send the request but at the moment he enter another space no need to send the request.
我正在尝试使用正则表达式来实现这一点。