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
I believe you need to excape the / with a \
regex = /(.*) # X \/ Y [abcde]/x
Jason
···
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
--
http://blog.casey-sweat.us/
You shouldn't have to with the /x modifier. It allows comments in the regex, and that / comes after a #.
James Edward Gray II
···
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
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-sweat.us/
Oh right, skipped right over that sublty 
···
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