Re: Doing an AND in regexp char class
by Joel VanderWerf other posts by this author
May 8 2008 5:26PM messages near this date
Re: Doing an AND in regexp char class
|
Re: Doing an AND in regexp char class
Todd Benson wrote:
> I'm drawing a blank here with this one. Why doesn't this work then...
>
> irb(main):006:0> r = /\A[oh]*\z/
> => /\A[oh]*\z/
> irb(main):007:0> s = "hello, there"
> => "hello, there"
> irb(main):008:0> r === s
> => false
Maybe I'm confused about was wanted originally. The above tests the
following condition:
(set of chars occurring in given string)
is_a_subset_of
(given set of chars).
irb(main):007:0> /\A[oh]*\z/ === "hohoho"
=> true
irb(main):008:0> /\A[oh]*\z/ === "ho ho"
=> false
If you want superset instead of subset, this works:
irb(main):013:0> /(?=.*h)(?=.*o)/ === "h o"
=> true
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
Thread:
Todd Benson
Rick DeNatale
Ara.T.Howard
Pit Capitain
Todd Benson
Joel VanderWerf
7stud --
David A. Black
7stud --
Todd Benson
David A. Black
Joel VanderWerf
Todd Benson
David A. Black
Joel VanderWerf
David A. Black
Ara.T.Howard
Robert Dober
|