Regex to *not* match any characters

前端 未结 10 1651
一个人的身影
一个人的身影 2020-12-24 11:18

I know it is quite some weird goal here but for a quick and dirty fix for one of our system we do need to not filter any input and let the corruption go into the system.

10条回答
  •  不知归路
    2020-12-24 11:44

    A simple and cheap regex that will never match anything is to match against something that is simply unmatchable, for example: \b\B.

    It's simply impossible for this regex to match, since it's a contradiction.

    References

    • regular-expressions.info\Word Boundaries
      • \B is the negated version of \b. \B matches at every position where \b does not.

提交回复
热议问题