What's happening here? A strange regexp problem wth posix :a

I just ran across this, and can’t figure out what’s happening. the
show_regexp method is as shown on p73 of the Pickaxe 2nd ed.

irb(main):013:0> show_regexp(“comparison is”, /[:alpha:][^.?!\s’"]/)
=> “com<> is”
irb(main):014:0> show_regexp(“comparison is”, /[:alpha:][^\s]
/)
=> “com<> is”
irb(main):015:0> show_regexp(“comparison is”, /[:alpha:][\S]/)
=> “com<> is”
irb(main):016:0> show_regexp(“comparison is”, /[a-zA-Z][\S]
/)
=> “<> is”
irb(main):017:0> show_regexp(“comparison is”, /[a-zA-Z][^\s]*/)
=> “<> is”

It looks like the Posix :alpha: character class doesn’t include c, o, or
m?!?

Or am I missing something?

Hey Rick,

On Aug 4, 2006, at 1:48 PM, Rick DeNatale wrote:

=> “<> is”

You need another pair of brackets around the :alpha:

So like this:

show_regexp(“comparison is”, /[[:alpha:]][\S]*/)

That tripped me up when I first used the Posix classes in Ruby, too.

– Brian

Brian P. wrote:

=> “com<> is”
Or am I missing something?
show_regexp(“comparison is”, /[[:alpha:]][\S]*/)

That tripped me up when I first used the Posix classes in Ruby, too.

It’s not just Ruby that requires the extra brackets.

echo BEGIN{print “123 f 987” ~ /[[:alpha:]]/} | gawk -f -
1

Thanks all, that makes sense.

On Aug 4, 2006, at 2:50 PM, William J. wrote:

It’s not just Ruby that requires the extra brackets.

echo BEGIN{print “123 f 987” ~ /[[:alpha:]]/} | gawk -f -
1

Yeah, I figured it was probably pretty standard, it really makes
sense–otherwise, the regex parser wouldn’t be able to tell if the
programmer really just wants to match against the specific
characters :, a, l, p, and h.

– Brian