[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

RegEx bug in 1.8.2?

Bill Atkins

11/12/2004 2:46:00 AM

bill@kaitain ruby $ ruby --version
ruby 1.8.2 (2004-11-06) [x86_64-linux]

bill@kaitain ruby $ cat regex_x_bug.rb
regex = /(.*) # X / Y
[abcde]/x

Running this code snippet yields:

regex_x_bug.rb:1: syntax error

If the / in the comment is changed to a -, the code compiles without
complaint It looks like Ruby is interpreting the / as the end of the
regex.

Bill


8 Answers

Jason Sweat

11/12/2004 2:54:00 AM

0

On Fri, 12 Nov 2004 11:46:25 +0900, Bill Atkins <batkins57@gmail.com> wrote:
> bill@kaitain ruby $ ruby --version
> ruby 1.8.2 (2004-11-06) [x86_64-linux]
>
> bill@kaitain ruby $ cat regex_x_bug.rb
> regex = /(.*) # X / Y
> [abcde]/x

I believe you need to excape the / with a regex = /(.*) # X \/ Y [abcde]/x

Jason
--
http://blog.casey...


James Gray

11/12/2004 2:57:00 AM

0

On Nov 11, 2004, at 8:54 PM, Jason Sweat wrote:

> I believe you need to excape the / with a > regex = /(.*) # X \/ Y [abcde]/x

You shouldn't have to with the /x modifier. It allows comments in the
regex, and that / comes after a #.

James Edward Gray II



Logan Capaldo

11/12/2004 3:07:00 AM

0

he shouldn't have to since he's using the /x modifier. Unfortunately I
think the problem is that Ruby has no way to know that /x is there
until it gets to it, and since it doesn't see it it assumes that / is
the end of the regex. Doing it any other way would require arbitrary
lookahead (I think, any parser guru's feel free to correct me).
Perhaps you can do something like Regexp.new "your regex in a string".
No I just tried that and it doesn't do it the right way. Aha! here we
go:
Regexp.new("(.*) # X / Y
[abcde]", Regexp::EXTENDED)

Yeah that works.

In the future I guess you'll have to avoid / in comments for extended
regular expressions, either that or escape them or use the method I
just outlined.

On Fri, 12 Nov 2004 11:54:00 +0900, Jason Sweat <jason.sweat@gmail.com> wrote:
> On Fri, 12 Nov 2004 11:46:25 +0900, Bill Atkins <batkins57@gmail.com> wrote:
> > bill@kaitain ruby $ ruby --version
> > ruby 1.8.2 (2004-11-06) [x86_64-linux]
> >
> > bill@kaitain ruby $ cat regex_x_bug.rb
> > regex = /(.*) # X / Y
> > [abcde]/x
>
> I believe you need to excape the / with a > regex = /(.*) # X \/ Y [abcde]/x
>
> Jason
> --
> http://blog.casey...
>
>


Jason Sweat

11/12/2004 3:11:00 AM

0

On Fri, 12 Nov 2004 11:57:07 +0900, James Edward Gray II
<james@grayproductions.net> wrote:
> On Nov 11, 2004, at 8:54 PM, Jason Sweat wrote:
>
> > I believe you need to excape the / with a > > regex = /(.*) # X \/ Y [abcde]/x
>
> You shouldn't have to with the /x modifier. It allows comments in the
> regex, and that / comes after a #.
>
> James Edward Gray II

Oh right, skipped right over that sublty :(


Yukihiro Matsumoto

11/12/2004 3:35:00 AM

0

Hi,

In message "Re: RegEx bug in 1.8.2?"
on Fri, 12 Nov 2004 11:57:07 +0900, James Edward Gray II <james@grayproductions.net> writes:

|> I believe you need to excape the / with a |> regex = /(.*) # X \/ Y [abcde]/x
|
|You shouldn't have to with the /x modifier. It allows comments in the
|regex, and that / comes after a #.

Current Ruby parser does not look into regex expression inside //, so
that Jason was right, for now at least.

matz.


ScotchBright

5/26/2011 2:27:00 AM

0

On Thu, 26 May 2011 01:43:30 +0000 (UTC), ScotchBright
<Bustercanreply@commonsense.com> wrote:

>ScotchBright <Bustercantreply@commonsense.com> wrote in
>news:uifpt6p4ki3901ugu7n3k35keiorc6mda5@4ax.com:
>
>Stop forging my name you halfwit stank cunt!
>

Still looking for a spanking?

ScotchBright

5/26/2011 2:51:00 AM

0

ScotchBright <Bustercantreply@commonsense.com> wrote in
news:1jert6dsttekv94skgntfcv707p65j06o5@4ax.com:

> On Thu, 26 May 2011 01:43:30 +0000 (UTC), ScotchBright
> <Bustercanreply@commonsense.com> wrote:
>
>>ScotchBright <Bustercantreply@commonsense.com> wrote in
>>news:uifpt6p4ki3901ugu7n3k35keiorc6mda5@4ax.com:
>>
>>Stop forging my name you halfwit stank cunt!
>>
>
> Still looking for a spanking?

Stop forging my name you halfwit stank cunt!

ScotchBright Canadian Fat Ugly Lesbo

5/27/2011 1:44:00 AM

0

The DemocRAT Hall Of Shame http://www.democrathallof... asks
"Why do you always LIE?"

[Courtesy of Buster Norris]

On Wed, 04 May 2011 02:08:15 -0400, ScotchBright
<Bustercantreply@commonsense.com> wrote:
>Re: They code named bin Laden "Geronimo"?
>Why? What did he represent to them?

LIAR!!!!!!!!!!!!!!!!!!

Operation Geronimo: How we got bin Laden
http://www.floridatoday.com/article/20110503/BREAKINGNEWS/110503002/Operation-Geronimo-How-we-got...

FOTD: What was the codename given to Osama Bin Laden during the
operation where U.S. Special Forces killed him?

While the operation had codename Geronimo, Osama Bin Laden was given
his own codename. That codename was, Jackpot.
http://factofthedayblog.com/755/pop-culture/fotd-what-was-the-codename-given-to-osama-bin-laden-during-the-operation-where-u-s-special-forces-k...

http://tinyurl.c...

Posted from:
The DemocRATs Hall of Shame!
http://www.democrathallof...