Re: Bug in packages with RegularExpression[]
- To: mathgroup at smc.vnet.net
- Subject: [mg78799] Re: Bug in packages with RegularExpression[]
- From: dr DanW <dmaxwarren at gmail.com>
- Date: Tue, 10 Jul 2007 06:24:01 -0400 (EDT)
- References: <f6npil$6uk$1@smc.vnet.net><f6sh82$7p4$1@smc.vnet.net>
On Jul 9, 12:31 am, Peter Pein <pet... at dordos.net> wrote: > dr DanW schrieb: > > > > > I have found a bug in Mathematica, version "6.0 for Mac OS X PowerPC > > (32-bit) (April 20, 2007)", where a legal syntax in a > > RegularExpression[] that is saved in a .m file is flagged as a error > > when the .m file is read in. To reproduce the error, create a file > > with the line > > > NumberStringQ[s_]:=StringQ[s]&&StringMatchQ[s,RegularExpression["[-+]? > > [0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?"]] > > > and save it as spam.m. Open a new notebook and input > > > <<spam.m > > > I get the error > > > Syntax::sntoct2: 2 hexadecimal digits are required after \. to > > construct an 8-bit character. > > > I have tried to simplify this further, with just a string containing > > the string "\.", but it seems to need the RegularExpression[] to > > generate the error. > > > The error also occurs in the 32 bit Windows version. > > Soryy, but the regexp doesn't seem correct to me. If you want the > decimal point, use either "\.2e" or "\\.". > > May I additionally suggest a small change to your regexp? > > NumberStringQ[s_] := StringQ[s] && StringMatchQ[s, > RegularExpression["[-+]?([0-9]*\\.?[0-9]+|[0-9]+\\.?[0-9]*)([eE][-+]?[0-9]+ )?"]] > > This allows ".1e5" /and/ "1.e4" which are common use. > > Regards, > Peter My bad. I figured this out right after I posted. I had forgotten to escape the "\." to "\\." Oddly, this did not cause an error in Mathematica, and my function performed as expected. It was only when I put the function into a package and attempted to read it back in that I got the error. Thank you for the tip on the leading decimal point. Regards, DW