How to ignore whitespace in a regular expression subject string?

后端 未结 6 628
梦毁少年i
梦毁少年i 2020-11-27 03:33

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\",

6条回答
  •  囚心锁ツ
    2020-11-27 04:23

    You could put \s* inbetween every character in your search string so if you were looking for cat you would use c\s*a\s*t\s*s\s*s

    It's long but you could build the string dynamically of course.

    You can see it working here: http://www.rubular.com/r/zzWwvppSpE

提交回复
热议问题