[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Possible bug in regexp engine?

Greg Hurrell

3/12/2007 1:23:00 PM

Given the following regular expression:

/([^*#]+|#(?!#|\*)|\*(?!#))+/

I wanted to make it more readable by inserting some comments, so I
tried adding the "x" option and it no longer compiled:

/([^*#]+|#(?!#|\*)|\*(?!#))+/x

If you try it in irb you'll see a message similar to this:

SyntaxError: compile error
(irb):31: unmatched (: /([^*#]+|#(?!#|\*)|\*(?!#))+/

To get this to compile I had to add additional backslashes to escape
the '#' character in the negative lookahead subexpressions:

/([^*#]+|#(?!\#|\*)|\*(?!\#))+/x

The '#' character normally matches itself in a regular expression.
With the "x" option I expect it to have a special meaning (indicating
a comment) but in one special position (immediately after the opening
brace and question mark):

(?# comment )

Is this a bug in the regular expression engine, undocumented or am I
missing something?

No big deal, the thing is compiling, but I'd like to understand this a
bit better.

Cheers,
Greg

4 Answers

Robert Klemme

3/12/2007 2:47:00 PM

0

On 12.03.2007 14:22, Greg Hurrell wrote:
> Given the following regular expression:
>
> /([^*#]+|#(?!#|\*)|\*(?!#))+/
>
> I wanted to make it more readable by inserting some comments, so I
> tried adding the "x" option and it no longer compiled:
>
> /([^*#]+|#(?!#|\*)|\*(?!#))+/x
>
> If you try it in irb you'll see a message similar to this:
>
> SyntaxError: compile error
> (irb):31: unmatched (: /([^*#]+|#(?!#|\*)|\*(?!#))+/
>
> To get this to compile I had to add additional backslashes to escape
> the '#' character in the negative lookahead subexpressions:
>
> /([^*#]+|#(?!\#|\*)|\*(?!\#))+/x
>
> The '#' character normally matches itself in a regular expression.
> With the "x" option I expect it to have a special meaning (indicating
> a comment) but in one special position (immediately after the opening
> brace and question mark):
>
> (?# comment )
>
> Is this a bug in the regular expression engine, undocumented or am I
> missing something?
>
> No big deal, the thing is compiling, but I'd like to understand this a
> bit better.

A "#" all by itself introduces a line comment as in normal code. So
everything after it is treated as a comment:

15:43:52 [~]: ruby -e 'r=/foo#bar
baz/x; p r; p r =~ "foobaz"'
/foo#bar
baz/x
0

The regexp matches "foobaz". /x allows line comments - (?#...) works always:

15:46:08 [~]: ruby -e 'r=/foo(?#bar)baz/; p r; p r =~ "foobaz"'
/foo(?#bar)baz/
0

Kind regards

robert

Greg Hurrell

3/12/2007 4:04:00 PM

0

On 12 mar, 15:47, Robert Klemme <shortcut...@googlemail.com> wrote:

> A "#" all by itself introduces a line comment as in normal code. So
> everything after it is treated as a comment

Thanks for the info, Robert.

Cheers,
Greg

The Revd

4/26/2013 10:33:00 PM

0

On Fri, 26 Apr 2013 10:25:17 -0400, "BIG TURD" <Snordo@Teranews.com>
wrote:

>
>"The Revd" <peeling@degenerate.Griks> wrote in message
>news:882ln8lbcnjcla7h1tof3okudra3eut0cl@4ax.com...
>: On Fri, 26 Apr 2013 09:50:52 -0400, "BIG TURD" <Snordo@Teranews.com>
>: wrote:
>:
>: >
>: >"The Revd" <peeling@degenerate.Griks> wrote in message
>: >news:fbqkn811aipuh95c0ijv5dra3a7cml0mfp@4ax.com...
>: >: On Thu, 25 Apr 2013 23:17:10 -0400, "BIG TURD" <Snordo@Teranews.com>
>: >: wrote:
>: >:
>: >: : >
>: >: >
>: >: >yall need to go do some holy rollin and some pew jumpin there gomer
>: >:
>: >: Anyone got a rope?
>: >:
>: >
>: >
>: >you better beg for one gomer, your trailer trash lard ass is too poor to buy
>one
>: >and too
>: >stupid to figure out how to use it
>: >
>: >git back to suckin that stinkin,slimy,filthy,angry,old,rich white man's dick
>like
>: >I done told yall boy
>:
>: Go suck on a watermelon, you stupid braindead coon.
>:
>
>it beats the hell out of suckin those stinkin,filthy,slimy,angry,old,rich white
>men's dicks
>which is the favorite pastime of all you low life, uneducated,cross eyed,bow
>legged,inbred,
>trailer trash hillbillies,crackers,and rednecks
>
>although you wouldn;t know that of course,
>
>you stick to the dirty rich dick boy, and keep hopin to get trickled on

Fuck you, niggerboi. Keep playin' that affirmative action shit. It's
the ONLY way they'll ever give you a job.

BIG Bird

4/27/2013 1:41:00 AM

0


"The Revd" <peeling@degenerate.Griks> wrote in message
news:h20mn8l77lae97ppb00boh3j46c9qif934@4ax.com...
: On Fri, 26 Apr 2013 10:25:17 -0400, "BIG TURD" <Snordo@Teranews.com>
: wrote:
:
:: >it beats the hell out of suckin those stinkin,filthy,slimy,angry,old,rich
white
: >men's dicks
: >which is the favorite pastime of all you low life, uneducated,cross eyed,bow
: >legged,inbred,
: >trailer trash hillbillies,crackers,and rednecks
: >
: >although you wouldn;t know that of course,
: >
: >you stick to the dirty rich dick boy, and keep hopin to get trickled on
:
: Fuck you, niggerboi. Keep playin' that affirmative action shit. It's
: the ONLY way they'll ever give you a job.


wwwwwwweeeeeellllllllll, as opposed to the
slimy,stinkin,filthy,rotten,angry,old,rich man's dick sucker
job you have,

anything is an improvement

so gomer, like what yall tell your mama,your wife and your daughters when you send
them out
the trailer
to try and make some money gittin their fat asses on their bony knees to suck a
rich man's dick
hopin he'll throw em some change ?????

LMAO