MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Bug in packages with RegularExpression[]

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78762] Re: Bug in packages with RegularExpression[]
  • From: Peter Pein <petsie at dordos.net>
  • Date: Mon, 9 Jul 2007 01:31:09 -0400 (EDT)
  • References: <f6npil$6uk$1@smc.vnet.net>

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


  • Prev by Date: Re: SolveAlways documentation problem
  • Next by Date: Re: Working with factors of triangular numbers.
  • Previous by thread: Bug in packages with RegularExpression[]
  • Next by thread: Re: Bug in packages with RegularExpression[]