On Nov 21, 9:51 pm, yermej <yer... / gmail.com> wrote: > On Nov 20, 8:00 pm, RichardOnRails > > <RichardDummyMailbox58... / uscomputergurus.com> wrote: > > > if line =~ /^ (.*?) [a-zA-Z] /x > > > I have one question about this regex. I have a book that I bought in > > 2002 but never read until today: "Mastering Regular Expressions", 2nd > > Ed., from O'Reilly. I haven't been able to find any reference in > > there to a question-mark following ".*". > > > I thought I could simply remove the question-mark. That caused the > > match to fail and yield the programmed error msg. I tried omitting > > the question-mark and add a closing "$" in the regex. That made the > > parsing fail. So, your question mark is clearly working, but HOW? > > I can help with this one. Check "Mastering Regular Expressions" for > non-greedy operators. Normally, ".*" will match everything it possibly > can. Adding the "?" causes it to do a minimal match -- it will match > as little as necessary to still fill the requirements. In the above > case, it matches everything until the first letter. Without the "?" it > matches everything until the last letter. > > Jeremy Hi Jeremy, > non-greedy operators. Thanks for that detailed explanation. I tried Googling for "(.*?) regular expression", but Google thiks it's too weird to actutally include "(.*?)" in a search ... and I don;t blame them. I checed Amazon to see if there is a later edition of "Masttering ...", to no avail. Again, thanks for taking the time to respond. Regards, Richard