How to ignore whitespace in a regular expression subject string?

后端 未结 6 627
梦毁少年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:15

    If you only want to allow spaces, then

    \bc *a *t *s\b
    

    should do it. To also allow tabs, use

    \bc[ \t]*a[ \t]*t[ \t]*s\b
    

    Remove the \b anchors if you also want to find cats within words like bobcats or catsup.

提交回复
热议问题