From: James Edward Gray II Date: 2004-09-19T08:51:58+09:00 Subject: Re: Method improvement request .-- On Sep 18, 2004, at 6:14 PM, Charles Hixson wrote: > James Edward Gray II wrote: > >> On Sep 18, 2004, at 5:04 PM, James Edward Gray II wrote: >> >>> What about something like: >>> >>> def parse1(chunk) >>> if chunk =~ / ^([^-A-Za-z0-9]*) # pre-match >>> (.*) # middle >> >> >> Sorry, that probably needs to be: >> >> (.*?) >> >> My bad. >> >> James Edward Gray II > > That would only work if the postmatch pattern were included in the > same pattern as the prematch, thus: > if chunk =~ /^([^-A-Za-z0-9.]*)(.*?)[^-A-Za-z0-9.]*)$/ I did include all three in the same pattern, I just used the whitespace and comment modifier to pretty it up a bit. /^([^-A-Za-z0-9.]*)(.*?)([^-A-Za-z0-9.]*)$/ Is the same as: / ^([^-A-Za-z0-9.]*) # pre-match (.*?) # middle ([^-A-Za-z0-9.]*)$ # post-match /x Note the trailing /x. James Edward Gray II