Regular expression to search for Gadaffi

后端 未结 15 1786
鱼传尺愫
鱼传尺愫 2020-12-07 07:05

I\'m trying to search for the word Gadaffi. What\'s the best regular expression to search for this?

My best attempt so far is:

\\b[KG]h?add?af?fi$\\         


        
15条回答
  •  Happy的楠姐
    2020-12-07 07:17

    Easy... (Qadaffi|Khadafy|Qadafi|...)... it's self-documented, maintainable, and assuming your regexp engine actually compiles regular expressions (rather than interpreting them), it will compile to the same DFA that a more obfuscated solution would.

    Writing compact regular expressions is like using short variable names to speed up a program. It only helps if your compiler is brain-dead.

提交回复
热议问题