--00163631081bde74ea04aa4ee1ca
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: quoted-printable

On Thu, Aug 11, 2011 at 5:52 AM, Glen Holcomb <damnbigman / gmail.com> wrote:

> On Thu, Aug 11, 2011 at 12:41 AM, 7stud -- <bbxx789_05ss / yahoo.com> wrote:
>
> > Also,
> >
> >
> > str = "hello\nhello"
> >
> > str.scan(/^hell/) {|match| p match}
> > puts "-" * 20
> > str.scan(/\Ahell/) {|match| p match}
> >
> > --output:--
> > "hell"
> > "hell"
> > --------------------
> > "hell"
> >
> > --
> > Posted via http://www.ruby-forum.com/.
> >
> >
> Hmmm... maybe I should have posted from the beginning rather than where I
> had gotten to in my attempt to solve my problem.
>
> I am tyring to parse log files and am pulling out encapsulated fields so
> that I can split the line in a sane way.  I have the following regex which
> I
> am using to do that:
>
> /\s(".*?")(\s|$)/
>
> Now as to why I'm looking for the \s before and the \s or $ after.  It
> turns
> out that some of the user agent strings are in a format like "\"Custom
> Agent\"=\"Mozilla ...\""\n
>
> I had been using the regex Ryan suggested earlier until I discovered the
> nested quotes.
>
> The expression above works for quoted strings surrounded by spaces but not
> the last one on the line.  I've tried changing $ to \n and that didn't make
> any difference.
>
> Here is the exact code I'm using:
>
> x = "encapsulatorhere"
> stash = {}
>
> gen_encap_matches.each do |encapex|
> line.gsub!(encapex) do |match|
> x.next!
> stash[x] = $1
> @job.log_format.separator + x + @job.log_format.separator
> end
> end
>
> gen_encap_matches just creates the regexes from a list of encapsulation
> characters.
>
> I'm at a complete loss as to why it won't grab the last quoted string in
> the
> line.
>
> --
> "Hey brother Christian with your high and mighty errand, Your actions speak
> so loud, I can√’ hear a word you√”e saying."
>
> -Greg Graffin (Bad Religion)
>


So, after a little digging on Stackoverflow I decided to try an explicit
lookahead.  For what ever reason it works.

/\s(".*?")(?=\s|$)/ matches where /\s(".*?")(\s|$)/ won't.


-- 
"Hey brother Christian with your high and mighty errand, Your actions speak
so loud, I can√’ hear a word you√”e saying."

-Greg Graffin (Bad Religion)

--00163631081bde74ea04aa4ee1ca--