如何忽略正则表达式主题字符串中的空格? - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章