Tag Info

New answers tagged

3

I'm not certain how general it is, but works :) Just for fun, I've assumed that FrontEnd should know what is a number and what to split on boxes: StringFreeQ[#, LetterCharacter] && c[#][[1, 1]] === # & /@ { "1.23", "1.23`", "1.23*^4", "Print[fail]", "string", "1`1", "1`1`1"} {True, True, True, False, False, True, False} Where c is ...


3

RegularExpression may be helpful, like this In[109]:= mylist = {"1.23", "1.23`", "1.23*^4", "1.22*^-2", "Print[fail]"}; numberString = RegularExpression[ "[0-9]*.?[0-9]*`?"] | (RegularExpression["[0-9]*.?[0-9]*`?"] ~~ "*^" ~~ RegularExpression["-?[0-9]+"]); StringMatchQ[mylist, numberString] Do[StringMatchQ[mylist, NumberString], {10^5}] // ...


3

Edit: I came to realize that my original form was redundant. I now propose this instead: p2 = NumberString ~~ "" | "`" | ("`" | "``" ~~ NumberString) ~~ "" | ("\\*^" | "\\*^-" ~~ DigitCharacter ..); Test: test = {"1.23`4.56*^-7", "1.23", "1.23`", "1.23``5", "1.23*^4", "Print[fail]"}; StringMatchQ[test, p2] {True, True, True, True, True, ...



Top 50 recent answers are included