[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RE question



--- Bobby Kleemann <neta.rkleeman@com> wrote:
> Doug was asking for a RegEx that would do what you had written,
> except he wanted it to start from the end of the comment and work
> backwards, matching as little as possible.  Since you cannot do a
> backwards RegEx in perl, just do a forwards one by reversing the text
> you are searching on.  
> 

    Essentially the situation, and that's an interesting idea you
propose. Interesting that C-style comments are still C-style comments
when written backwards. =) I'll try it tomorrow...

> 
> > if it's the same expression, why did you say it wouldn't work?
> > and i don't understand you forward and backward ungreedyness... 
> > 
> > your original example had one comment in it, and that worked for
> > one comment. if you mean having multiple comments, then the
> > simplest way to do it is with a loop.. i'm not sure if i just
> > misunderstood you or not..
> > 

    You're right, my original example was poor. Here's a better one:

/* Bob's comment. */
void bob(){}

/* Jack's comment. */
void jack(){}

/* Jill's comment. */
void jill(){}

    So, what I'm trying to do is extract the comment before any
arbitrary function name. I've read that whole file into a string, and I
have, say, 'jill' stored into a variable, and from that I want to
extract "/* Jill's comment. */". Your RE, the one I tried originally,
would extract all the way from "/* Bob's comment..." to "... Jill's
comment. */". Try the whole RE I put in my first email and see.

    Since I can't think of it right now, and I'm not on a box with Perl
at the moment, what's the best way to reverse a string? =)

$rev = join('', reverse split(//, $string));

    Something like that'll surely work, but the string may be something
like 140k... eh, whatever. I'll just try it. =)

    Thanks guys.

===

Doug

_________________________________________________________
Do You Yahoo!?
Get your free yahoo.@com address at http://mail.yahoo.com