本文介紹了正則表達式匹配最后一個空格字符的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我需要一些幫助.我正在尋找一個匹配字符串中最后一個空格字符的正則表達式.我正在使用 JavaScript 和經典 ASP.
I need some help. I am looking for a regex that would match the last space character in a string. I am using JavaScript and classic ASP.
我有一長串文本,我將其修剪為 100 個字符.如果修剪由于 100 個字符的限制而剪切了一個單詞,我想刪除最后一個字符以避免拼寫錯誤.
I have a long string of text which I trim to 100 characters. I would like to remove the last character to avoid a spelling mistake if the trim cuts a word due to the 100 characters limit.
regex.replace(/[ ]$.*?/ig, '');
有人有想法嗎?謝謝.
推薦答案
根據我的理解,你需要刪除最后一個空格和后面的所有內容,對吧?
From my understanding, you need to remove the last space and everything after it, right?
str = str.replace(/s+S*$/, "")
這篇關于正則表達式匹配最后一個空格字符的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!