Forum: Ruby challenge - regex which matches nothing

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
unknown (Guest)
on 2005-12-15 22:01
(Received via mailing list)
this is the best i've come up with

   %r/^(?!.*)$/m

comments?

-a
unknown (Guest)
on 2005-12-15 22:04
(Received via mailing list)
Hi --

On Fri, 16 Dec 2005, removed_email_address@domain.invalid wrote:

>
>
> this is the best i've come up with
>
>  %r/^(?!.*)$/m

How about:

   /[^\w\W]/


David

--
David A. Black
removed_email_address@domain.invalid

"Ruby for Rails", forthcoming from Manning Publications, April 2006!
Mike F. (Guest)
on 2005-12-15 22:15
unknown wrote:
> this is the best i've come up with
>
>    %r/^(?!.*)$/m

%r/\z\A/ ?
C Erler (Guest)
on 2005-12-15 22:20
(Received via mailing list)
On 15/12/05, removed_email_address@domain.invalid 
<removed_email_address@domain.invalid> wrote:
> ===============================================================================
> | ara [dot] t [dot] howard [at] noaa [dot] gov
> | all happiness comes from the desire for others to be happy.  all misery
> | comes from the desire for oneself to be happy.
> | -- bodhicaryavatara
> ===============================================================================
>
>
>

/\1/ seems to work.
unknown (Guest)
on 2005-12-15 22:38
(Received via mailing list)
On Fri, 16 Dec 2005 removed_email_address@domain.invalid wrote:

> How about:
>
>  /[^\w\W]/

hmmm.  seems to work.  clever.

-a
unknown (Guest)
on 2005-12-15 22:38
(Received via mailing list)
On Fri, 16 Dec 2005, Mike F. wrote:

> unknown wrote:
>> this is the best i've come up with
>>
>>    %r/^(?!.*)$/m
>
> %r/\z\A/ ?

close

   irb(main):020:0> "" =~ %r/\z\A/
   => 0


-a
unknown (Guest)
on 2005-12-15 22:41
(Received via mailing list)
On Fri, 16 Dec 2005, C Erler wrote:

>> --
> /\1/ seems to work.
you win the golf contest i think... that seems to be the shortest
possible...

wow.

-a
Bob S. (Guest)
on 2005-12-15 22:44
(Received via mailing list)
removed_email_address@domain.invalid wrote:
> On Fri, 16 Dec 2005, C Erler wrote:
>> /\1/ seems to work.
>
>
> you win the golf contest i think... that seems to be the shortest
> possible...

Same number of chars:

   /.^/
unknown (Guest)
on 2005-12-15 22:50
(Received via mailing list)
On Fri, 16 Dec 2005, Bob S. wrote:

>  /.^/
it's 'smaller' too...


-a
Chad P. (Guest)
on 2005-12-15 22:56
(Received via mailing list)
On Fri, Dec 16, 2005 at 05:50:04AM +0900, removed_email_address@domain.invalid 
wrote:
> >Same number of chars:
> >
> > /.^/
>
>
> it's 'smaller' too...

. . . and "cuter".

--
Chad P. [ CCD CopyWrite | http://ccd.apotheon.org ]

unix virus: If you're using a unixlike OS, please forward
this to 20 others and erase your system partition.
mathew (Guest)
on 2005-12-16 23:48
(Received via mailing list)
removed_email_address@domain.invalid wrote:
> comments?

I think you mean 'a regex which doesn't match anything'; surely
/^$/ is a regex which matches nothing?


mathew
James G. (Guest)
on 2005-12-17 00:00
(Received via mailing list)
On Dec 16, 2005, at 3:47 PM, mathew wrote:

> removed_email_address@domain.invalid wrote:
>> comments?
>
> I think you mean 'a regex which doesn't match anything'; surely
> /^$/ is a regex which matches nothing?

No, he meant a regex that always fails.

Yours matches empty lines.

James Edward G. II
unknown (Guest)
on 2005-12-17 00:03
(Received via mailing list)
On Sat, 17 Dec 2005, mathew wrote:

> removed_email_address@domain.invalid wrote:
>> comments?
>
> I think you mean 'a regex which doesn't match anything'; surely
> /^$/ is a regex which matches nothing?

indeed i did - but i thought that a subject like that would lead to
people
skiiming it and thinking i was having problems with my regex - that it
didn't
match anything!

whose on first?

-a
unknown (Guest)
on 2005-12-17 00:06
(Received via mailing list)
On Sat, 17 Dec 2005, James Edward G. II wrote:

> On Dec 16, 2005, at 3:47 PM, mathew wrote:
>
>> removed_email_address@domain.invalid wrote:
>>> comments?
>>
>> I think you mean 'a regex which doesn't match anything'; surely
>> /^$/ is a regex which matches nothing?
>
> No, he meant a regex that always fails.

lol!

ok.  before this gets out of hand, what i meant was

   regex =~ any_possible_string #=> false

kind regards.

-a
Reinder V. (Guest)
on 2005-12-17 01:16
(Received via mailing list)
In article <removed_email_address@domain.invalid>,
 removed_email_address@domain.invalid wrote:

> > No, he meant a regex that always fails.
>
> lol!
>
> ok.  before this gets out of hand, what i meant was
>
>    regex =~ any_possible_string #=> false
>
<nitpick>That never happens in Ruby. =~ returns nil if the expression
and the string passed to it do not match.</nitpick>

I would guess that it should be possible to put all possible characters
between [ and ], and negate that.

I think /\z\a/ should do the trick, too (from experimentation, I can not
find anything that matches it, but maybe I haven't thought/experimented
enough about/with it)

Finally, I think one can to build a not-too-long regex that only matches
strings of length larger than addressable memory, using something like:

/((x{1000000000}){1000000000}){1000000000}/

If you repeat that pattern a couple of times you get a regular
expression that, for all practical purposes, will match nothing.

Reinder
This topic is locked and can not be replied to.