Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chanukah Regex [closed]

Tags:

regex

Hannuka, Chanukah, Hanukkah...Due to transliteration from another language and character set, there are many ways to spell the name of this holiday. How many legitimate spellings can you come up with?

Now, write a regular expression that will recognise all of them.

like image 869
gbarry Avatar asked Dec 23 '08 02:12

gbarry


2 Answers

According to http://www.holidays.net/chanukah/spelling.htm, it can be spelled any of the following ways:

Chanuka
Chanukah
Chanukkah
Channukah
Hanukah
Hannukah
Hanukkah
Hanuka
Hanukka
Hanaka
Haneka
Hanika
Khanukkah

Here is my regex that matches all of them:

/(Ch|H|Kh)ann?[aeiu]kk?ah?/

Edit: Or this, without branches:

/[CHK]h?ann?[aeiu]kk?ah?/
like image 59
Paige Ruten Avatar answered Sep 21 '22 08:09

Paige Ruten


Call me a sucker for readability.

In Python:

def find_hanukkah(s):
   import re

   spellings = ['hannukah', 'channukah', 'hanukkah'] # etc...

   for m in re.finditer('|'.join(spellings), s, re.I):
      print m.group()



find_hanukkah("Hannukah Channukah, Hanukkah")
like image 29
Kenan Banks Avatar answered Sep 24 '22 08:09

Kenan Banks