我正在尝试确定最后一个空白字符和字符串末尾之间的字符。
例子
Input: "this and that"
Output: "that"
我试过下面的正则表达式,但它不起作用!
var regex = /[\s]$/
最佳答案
可以不用正则表达式
var result = string.substring(string.lastIndexOf(" ")+1);
使用正则表达式
result = string.match(/\s[a-z]+$/i)[0].trim();
关于javascript - 正则表达式捕获最后一个空白字符和字符串结尾之间的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13102564/