3
$\begingroup$

This question already has an answer here:

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

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

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

$\endgroup$

marked as duplicate by WReach, Michael E2, MarcoB, Leonid Shifrin, m_goldberg Dec 26 '15 at 0:17

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 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.