Consider the string


I would like to make a row

{distr,massvalue, thetavalue};

I write

 mixing__ ~~ "_distribution_mass=" ~~ mass : NumberString ~~ 
   "_theta=" ~~ angle : NumberString ~~ ".txt" :> {mixing, 
   ToExpression[mass], ToExpression[angle]}]

but the problem is that NumberString does not recognize the scientific form of numbers, because of which the code returns empty. Could you please tell me what is an analog of NumberString in this example?

  • 2
    $\begingroup$ Rather than StringCases, I would use: MapAt[Interpreter["Number"],StringSplit[string,{"_distribution_mass=","_theta=",".txt"}] ,{2;;3}] $\endgroup$
    – chuy
    Commented May 4, 2021 at 16:37

1 Answer 1


This is a case for RegularExpression:

s = "Tau_distribution_mass=547.0_theta=6.87982e-05.txt";
regex = RegularExpression[

StringCases[s, regex -> "$1,$2,$3"]


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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