[英]Regex to capture characters between the last white space character and the end of string
我正在嘗試確定最后一個白色空間字符和字符串結尾之間的字符。
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();
您可以刪除所有內容到最后一個空格。
s.replace(/.* /, '')
或者,匹配任何空白區域......
s.replace(/.*\s/, '')
您的示例僅匹配字符串末尾的一個空格字符。 使用
/\s\S+$/
匹配任何數字。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.