3
$\begingroup$

For the string ((!@#)), the shortest match for the pattern "("~~__~~")" should be "(!@#)", but

StringCases["((!@#))", Shortest["(" ~~ __ ~~ ")"]]

Returns with ((!@#). What went wrong with my code? Thanks!

$\endgroup$
2
  • 6
    $\begingroup$ duplicate of (72283). $\endgroup$
    – WReach
    Dec 25 '15 at 20:26
  • 1
    $\begingroup$ A concise explanation of what went wrong with your code is in the question mathematica.stackexchange.com/q/18193/5467. The question suggests a solution with Except[]. The complete suggested solution is : StringCases["((!@#))", Shortest["(" ~~ Except["("] .. ~~ ")"]] $\endgroup$
    – andre314
    Dec 26 '15 at 13:44
4
$\begingroup$
Last@StringCases["((!@#))", Shortest["(" ~~ __ ~~ ")"], Overlaps -> True]

enter image description here

$\endgroup$

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