Forum: Ruby on Rails Stange regexp problem with case sensitivity

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.
James B. Byrne (Guest)
on 2006-02-08 23:39
(Received via mailing list)
Environment:
CentOS 4.2 (RHES4 clone)
Ruby 1.8.4
Rails 1.0

I am having a small difficulty with case sensitive matching in some
ruby code:

f_nam_re = Regexp.new(f_nam_re_s,"x")

produces these test results:

The passed regexp: ^QPCCCMR[[:digit:]]$
The regexp used is:
/^QPCCCMR[[:digit:]]$/i
$= is false

qpcccmr1 matches
QPCCCMR1 matches
QPCCMMR1 does not match
qpCCCMR1 matches
QPCCCMRC does not match
QPCCCMR1.csv does not match
QPCCCMR9 matches
XXQPCCCMR9 does not match
QPCCCMR9yyy does not match
XyZQPCCCMR3AbC does not match

However, just removing the "x"
f_nam_re = Regexp.new(f_nam_re_s)

Produces this from the same test suite:

The passed regexp: ^QPCCCMR[[:digit:]]$
The regexp used is:
/^QPCCCMR[[:digit:]]$/
$= is false

qpcccmr1 does not match
QPCCCMR1 matches
QPCCMMR1 does not match
qpCCCMR1 does not match
QPCCCMRC does not match
QPCCCMR1.csv does not match
QPCCCMR9 matches
XXQPCCCMR9 does not match
QPCCCMR9yyy does not match
XyZQPCCCMR3AbC does not match

So, why does enabling regexp extensions force case insensitivity?
Further, once it is turned on in this fashion I cannot seem to get
it switched off even when using the (?-i:) construct.

I would very much appreciate a direct copy of any reply to the list
as I subscribe to the digest version of.

Regards,
Jim

--
     *** e-mail is not a secure channel ***
mailto:byrnejb.<token>@harte-lyne.ca
James B. Byrne                Harte & Lyne Limited
vox: +1 905 561 1241          9 Brockley Drive
fax: +1 905 561 0757          Hamilton, Ontario
<token> = hal                 Canada L8E 3C3
This topic is locked and can not be replied to.