Re: Re: need some regex help to strip out // comments but not http:// urls
| From: | Sean Greenslade | Date: | Wed, 29 May 2013 17:46:32 +0000 |
| Subject: | Re: Re: need some regex help to strip out // comments but not http:// urls | ||
| References: | 1 2 3 4 5 6 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-321244@lists.php.net to get a copy of this message | ||
On Wed, May 29, 2013 at 1:33 PM, Matijn Woudt <tijnema@gmail.com> wrote:
>
>
>
> On Wed, May 29, 2013 at 7:27 PM, Sean Greenslade <zootboysean@gmail.com>
> 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..
>> >
<SNIP>
> 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
Sorry, I slightly mis-interpreted what that code was intending to do.
Regardless, it is still something that should be done by an
interpreter. So this is another edge case where regexes would more
than likely break down but an interpreter should (I do say should) do
The Right Thing.
--
--Zootboy
Sent from some sort of computing device.