Re: Re: need some regex help to strip out // comments but not http:// urls

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

 



On Wed, May 29, 2013 at 7:27 PM, Sean Greenslade <zootboysean@xxxxxxxxx>wrote:

> > It is possible to write a whole parser as a single regex, being it
> terribly
> > long and complex.
> > That said, there's no other simple syntax that would work, for example in
> > javascript you could to the following:
> > var http = 5;
> > switch(value) {
> >     case http:// Http case here! (this whould not be deleted)
> >         // Do something
> > }
> > But most likely you wouldn't care about that..
> >
> > - Matijn
>
> I would have to disagree. There are things that regex just can't at a
> fundamental level grok. Things like nested brackets (e.g. the standard
> blocking syntax of C, javascript, php, etc.). It's not a parser, and
> despite all the little lookahead/behind tricks that enhanced regex can
> do, it can't at a fundamental level _interret_ the text it sees. This
> task involves interpreting what the text you're looking for actually
> means, and should therefore be handled by something that can
> interpret.
>

I think it should be possible, but as I said, very very complex. Let's not
try it;)

>
> Also, (I haven't tested it, but) I don't think that example you gave
> would work. Without any sort of quoting around the "http://";
> , I would assume the JS interpreter would take that double slash as a
> comment starter. Do tell me if I'm wrong, though.
>
> Which is exactly what I meant. Because http is a var set to 5, it is a
valid case statement, it would be equal to:
switch(value) {
    case 5: // Http case here! (this whould not be deleted)
        // Do something
}

But any regex given above would treat the first one as a http url, and
won't strip the // and everything after it, though in this modified case it
will strip the comments.

- Matijn

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux