Regular expression to search for Gadaffi

后端 未结 15 1801
鱼传尺愫
鱼传尺愫 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条回答
  •  情深已故
    2020-12-07 07:24

    Why not do a mixed approach? Something between a list of all possibilities and a complicated Regex that matches far too much.

    Regex is about pattern matching and I can't see a pattern for all variants in the list. Trying to do so, will also find things like "Gazzafy" or "Quud'haffi" which are most probably not a used variant and definitly not on the list.

    But I can see patterns for some of the variants, and so I ended up with this:

    \b(?:Gheddafi|Gathafi|Kazzafi|Kad'afi|Qadhdhafi|Qadthafi|Qudhafi|Qu?athafi|[KG]h?add?h?aff?[iy]|Qad[dh]?afi)\b
    

    At the beginning I list the ones where I can't see a pattern, then followed by some variants where there are patterns.

    See it here on www.rubular.com

提交回复
热议问题