如何忽略正則表達式主題字符串中的空格? - How to ignore whitespace in a regular expression subject string?

問題:

Is there a simple way to ignore the white space in a target string when searching for matches using a regular expression pattern? 使用正則表達式模式搜索匹配項時,是否有一種簡單的方法可以忽略目標字符串中的空格? For example, if my search is for "cats", I would want "c ats" or "ca ts" to match. 例如,如果我搜索的是“貓”,則希望匹配“貓”或“貓”。 I can't strip out the whitespace beforehand because I need to find the begin and end index of the match (including any whitespace) in order to highlight that match and any whitespace needs to be there for formatting purposes. 我無法預先去除空格,因爲我需要找到匹配項的開始和結束索引(包括任何空格)以突出顯示該匹配項,並且任何空格都需要用於格式化。


解決方案:

參考: https://stackoom.com/en/question/JG94
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章