From: Paul Sutton Date: 2012-06-14T01:11:25+09:00 Subject: Re: Problem with reg exp On Wed, 2012-06-13 at 13:21 +0900, Matthew Kerwin wrote: > I'd have to think a lot harder about how you're getting what you're > getting with str2, but I'm already pretty sure the actual question can > be resolved using =~ or String#match In this case: "ABC13B2013KEYWORD".split(/([a-zA-Z]+)(.*)(KEYWORD?)/) => ["","ABC","12A2012","KEYWORD"] what is happening is that split's results consist of both the strings between the matched delimiters, and (for each match of the delimiter) any match groups from the delimiters themselves. In this case, the regex matches the entire string. Without match groups it would give: "ABC13B2013KEYWORD".split(/[a-zA-Z]+.*KEYWORD?/) => [""] (An empty string since the delimiter matched from the start of the string. Logically there should be a second empty string for the match at the end of the string, but that is suppressed unless you give the second arg to split). -Paul