6
$\begingroup$

This code works fine in a string based interface like WolframScript or Mathematica Kernel.

Run this through a string based interface

StringCases["hello", x_..]    

Or do

ToExpression["StringCases[\"hello\", x_..]"]

in the notebook. Both work correctly, x_.. is interpreted as a Repeated form of the pattern x_,

Try it online!

In the notebook based front end, however, it fails because x_. is interpreted as a Default pattern and the second dot throws a syntax error.

enter image description here

The code must be modified to

StringCases["hello", (x_)..]
(*    {"h", "e", "ll", "o"}    *)

Why is there a difference in behavior between the front end and kernel parsers.

$\endgroup$

Your Answer

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

Browse other questions tagged or ask your own question.