From: yermej Date: 2007-11-22T11:55:00+09:00 Subject: Re: False positives in editing data On Nov 20, 8:00 pm, RichardOnRails 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