From: Charles Hixson Date: 2004-09-20T06:03:53+09:00 Subject: Re: Method improvement request .-- James Edward Gray II wrote: > 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 Sorry. It took me a bit of digging to find the /.../x documentation even after you explicitly pointed it out to me. (This won't work for me, because my actual pre- and post- patterns also exclude spaces, but it can certainly clarify the example, if one understands it!)