lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Florian Berger wrote:
I have a simple question about string searching. Let's say that I want to know if city "Muenchen" is found in text. If I don't know the source of text the city might be written like "Muenchen" or "München". I would like to make my search support both versions with single search pattern. Something like: string.find(txt, "m[ü or ue]nchen"). The problem is that the alternatives don't have the same length. Otherwise they could be put to a set. Is there any simple solution to this problem?

You may use POSIX regexp or PCRE binding for Lua, such as Lrexlib:

local pcre = require 'pcre'
local r = pcre.newPCRE("m(ü|ue)nchen")
local Start,End = r:match(txt)

--
Shmuel