From: Stefano Crocco Date: 2008-01-25T22:43:46+09:00 Subject: Re: regex issue Alle Friday 25 January 2008, Junkone ha scritto: > my pattern should match either import or delete > However it does not seem to be working. > > irb(main):014:0> pattern="([import]|[delete])" > => "([import]|[delete])" > irb(main):015:0> pattern.match("import") > => # > irb(main):016:0> $1 > => nil I see two problems with your code: 1) if you want to check that a string (in your case, 'import') matches a pattern, you need to use string.match(pattern) which, in your case, is 'import'.match(pattern) 2) in a regexp, the construct [abc] means one character among 'a', 'b' or 'c', not (as I guess you think) the string 'abc'. Because of this, the string 'i' matches your pattern: 'i'.match(pattern) => # To do what you want, you simply need: pattern = "(import|delete") "import".match pattern =># $1 => "import" I hope this helps Stefano