3

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

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

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

arax
  • 1,831
  • 12
  • 16
  • 6
    duplicate of (72283). – WReach Dec 25 '15 at 20:26
  • 1
    A concise explanation of what went wrong with your code is in the question http://mathematica.stackexchange.com/q/18193/5467.
    The question suggests a solution with Except[]. The complete suggested solution is : StringCases["((!@#))", Shortest["(" ~~ Except["("] .. ~~ ")"]]
    – andre314 Dec 26 '15 at 13:44

1 Answers1

4
Last@StringCases["((!@#))", Shortest["(" ~~ __ ~~ ")"], Overlaps -> True]

enter image description here

eldo
  • 67,911
  • 5
  • 60
  • 168