7 msg[Challenge] Cookie Monster!
1 msgRuby Quiz 2.0 new location
1 msgHoe and multiple gems

Doing an AND in regexp char class
\ Todd Benson (8 May 2008)
. \ ara.t.howard (8 May 2008)
. . \ Todd Benson (8 May 2008)
. . . \ ara.t.howard (8 May 2008)
. . . . \ Robert Dober (9 May 2008)
. . . \ Joel VanderWerf (9 May 2008)
. . . . \ Todd Benson (9 May 2008)
. . . . . \ Joel VanderWerf (9 May 2008)
. . . . . . \ David A. Black (9 May 2008)
. . . . . . . \ Joel VanderWerf (9 May 2008)
. . . . . . . . \ David A. Black (9 May 2008)
. . . . . . \ Todd Benson (9 May 2008)
. . . . . \ David A. Black (9 May 2008)
. . . . \ 7stud -- (9 May 2008)
. . . . . \ David A. Black (9 May 2008)
. . . . . . \ 7stud -- (9 May 2008)
. . \ Pit Capitain (11 May 2008)
. \ Rick DeNatale (8 May 2008)

2 msgqt ruby gem install on windows xp
1 msgWrite Ruby code sentences
5 msgwired result
11 msgscramble sentence, how to better program?
2 msgwindows prompt, how to write [ ] ?
9 msg[ANN] tagz-4.2.0 - giraffe slayer
1 msgRe: checking connection to server:port [socket]
3 msgHow call scripts in windows using something lik...
2 msgRe: Error when starting the server
3 msgQtRuby: get data from TableWidget
9 msgCompilation error in cont.c
6 msgWriting a SQL Query in Active Record?
5 msgintegers with preceding zero don't return as ex...
12 msgComparing String with Symbol
1 msgAUTO: Joe Grastara is out of the office (return...
6 msgeclipse rdt is painful
Subject:Doing an AND in regexp char class
Group:Ruby-talk
From:Todd Benson
Date:8 May 2008


 
This question arises out of a couple of recent threads and may or may
not be a Ruby-specific question.

I can check with a character class if one of the characters in the
class exists or does not exist, but can I use a regexp to check if a
string absolutely contains all of the characters in the class?

Using a set perspective, I can do it like this in irb...

s1 = "hello there"
s2 = "ohi"
(s2.unpack('c*') & s1.unpack('c*')).size == s2.size

=> false

I use unpack to avoid creating a bunch of String objects, one for each
element in the array, which would happen if I used #split. What I'm
wondering is if there is a way to do this with a simple regexp.

Thanks,
Todd



© 2004-2008 readlist.com