From: Matthew Kerwin Date: 2012-06-13T12:56:48+09:00 Subject: Re: Problem with reg exp I have a couple of comments/questions: 1. how are you actually getting those substrings? I'm pretty sure you want to use a match, like =~ (or equivalent) rather than String#split 2. I suspect that (KEYWORD?) doesn't do what you expect. It matches either "KEYWORD" or "KEYWOR". On 13 June 2012 11:30, cyber c. wrote: > Hi, > > I need to match > > str1 = "ABC12A2012" > str2 = "ABC13B2013KEYWORD" > > i have to extract, > word1 = ABC, word2 = 12A2012 for str1 > word1 = ABC, word2 = 13B2013 for str2 > > i have used > str.split(/([a-zA-Z]+)(.*)(KEYWORD?)/) > > for str2 i get substrings as > "","ABC","12A2012","KEYWORD" --  Why did the nil sub string popped up? > > for str1 i get only 1 substring which is the entire string > > Any one can spot the problem , please let me know. > > -- > Posted via http://www.ruby-forum.com/. > --   Matthew Kerwin, B.Sc (CompSci) (Hons)   http://matthew.kerwin.net.au/   ABN: 59-013-727-651   "You'll never find a programming language that frees   you from the burden of clarifying your ideas." - xkcd