[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: usage of Regexp::EXTENDED

Dave Thomas

10/8/2003 1:02:00 PM


On Wednesday, Oct 8, 2003, at 07:49 US/Central, Simon Strandgaard wrote:
> assert_match(/b \nc/x, "abcd")
>
> fails ?
>
> programming-ruby says that newlines will be ignored?
>

Physical newlines. The \n is part of the pattern

assert_match(/b
c/x, "abcd")


4 Answers

Simon Strandgaard

10/8/2003 1:31:00 PM

0

On Wed, 08 Oct 2003 23:02:27 +0900, Dave Thomas wrote:

>
> On Wednesday, Oct 8, 2003, at 07:49 US/Central, Simon Strandgaard wrote:
>> assert_match(/b \nc/x, "abcd")
>>
>> fails ?
>>
>> programming-ruby says that newlines will be ignored?
>>
>
> Physical newlines. The \n is part of the pattern
>
> assert_match(/b
> c/x, "abcd")


I was blind, and now I see. Thanks comp.lang.ruby ;-)

--
Simon Strandgaard

Simon Strandgaard

10/8/2003 1:52:00 PM

0

Feeding the same string into // and into Regexp.new,
yields to different results. A bit inconsist..


def test_option_extended3
# ignoring newline
re = Regexp.new("b\nc", Regexp::EXTENDED)
assert_match(re, "abcd")
end
def test_option_extended4
# does not ignore newline... makes no sense?
assert_no_match(/b\nc/, "abcd")
end


Just my thought ;-)

--
Simon Strandgaard




Simon Strandgaard

10/8/2003 2:02:00 PM

0

On Wed, 08 Oct 2003 16:51:52 +0200, Simon Strandgaard wrote:

> Feeding the same string into // and into Regexp.new,
> yields to different results. A bit inconsist..
>>inconsistent<<
>
>
> def test_option_extended3
> # ignoring newline
> re = Regexp.new("b\nc", Regexp::EXTENDED)
> assert_match(re, "abcd")
> end
> def test_option_extended4
> # does not ignore newline... makes no sense?

assert_no_match(/b\nc/x, "abcd")

I forgot the 'x' ^^^

> end
>
>
> Just my thought ;-)


revision 0.2: spell correction.

--
Simon Strandgaard


mark sparshatt

10/8/2003 3:15:00 PM

0

Simon Strandgaard wrote:
> Feeding the same string into // and into Regexp.new,
> yields to different results. A bit inconsist..
>
>
> def test_option_extended3
> # ignoring newline
> re = Regexp.new("b\nc", Regexp::EXTENDED)
> assert_match(re, "abcd")
> end

In this case the \n will have already been replaced by a literal
newline. So Regexp.new receives

"a
b"

as it's first parameter.


> def test_option_extended4
> # does not ignore newline... makes no sense?
> assert_no_match(/b\nc/, "abcd")
> end
>

In this case the \n won't have been interpolated before constructing the
regexp.

Best Regards

Mark Sparshatt