8
$\begingroup$

There is a regular expression that I used often in Mathematica 8, made to locate matching curly braces:

RegularExpression["(?P<0>{([^{}]|(?P>0))*})"]

However, it is no longer working in Mathematica 10.4. It returns an error

RegularExpression::msg84: Group name must start with a non-digit [[etc.]] 

Any clue what is going on?

$\endgroup$
  • 2
    $\begingroup$ Would you give us an example of how you use the RE you show fails. I do not find "to locate matching curly braces" sufficient to be able to reproduce the problem $\endgroup$ – m_goldberg May 28 '17 at 23:03
  • $\begingroup$ I don't find that RegularExpression["(?P<0>{([^{}]|(?P>0))*})"] returns an error in my copy of 10.4 (Mac OS 10.10) $\endgroup$ – QuantumDot May 28 '17 at 23:46
  • $\begingroup$ Replace the 0 in name with something with a non-digit initial... $\endgroup$ – ciao May 28 '17 at 23:47
11
$\begingroup$

Fix the group name. Beats me why the change - first works in 9.X Win., but not on 10.3 Win...

StringPosition["{tes,{1,2,3},t}", RegularExpression["(?P<0>{([^{}]|(?P>0))*})"]]

RegularExpression::msg84: Group name must start with a non-digit in RegularExpression[(?P<0>{([^{}]|(?P>0))*})]. >>

StringPosition["{tes,{1,2,3},t}", RegularExpression["(?P<grp0>{([^{}]|(?P>grp0))*})"]]

{{1, 15}, {6, 12}}

$\endgroup$
  • 5
    $\begingroup$ PCRE used to allow names starting with digits. But version 8.34 of PCRE disallowed them -- to match the same change which was made in Perl. It appears that Mathematica 10.1 was the first release to use PCRE 8.34 or later. $\endgroup$ – WReach May 29 '17 at 3:07
  • $\begingroup$ @WReach - Thought as much, but did not want to shoot the mouth without knowing it to be true. Thanks for confirmation. $\endgroup$ – ciao May 29 '17 at 7:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.