Regex to *not* match any characters

前端 未结 10 1579
一个人的身影
一个人的身影 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:33

    Empty regex

    The best regex to never match anything is an empty regex. But I'm not sure all regex engine will accept that.

    Impossible regex

    The other solution is to create an impossible regex. I found that $-^ only takes two steps to compute regardless of the size of your text (https://regex101.com/r/yjcs1Z/1).

    For reference:

    • $^ and $. take 36 steps to compute -> O(1)
    • \b\B takes 1507 steps on my sample and increase with the number of character in your string -> O(n)

提交回复
热议问题