Re: StringCases and Shortest
- To: mathgroup at smc.vnet.net
- Subject: [mg97356] Re: StringCases and Shortest
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Wed, 11 Mar 2009 05:08:40 -0500 (EST)
- Organization: Uni Leipzig
- References: <gp8047$1k9$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi, StringCases["(-(a)--(bb)--(c)-", Shortest["(" ~~ q__ ~~ ")"] /; StringFreeQ[q, "("]] ?? Regards Jens Grischika at mail.ru wrote: > Hello! > I want to select shortest substring between brackets from the string. > For example: > > Func["f(a+b) some text (comments)" ] > > should give: > > {"a+b","comments"}, > > and > > Func["(f(a+b) some text (comments)" ] > > should give: > > {"(a+b)","(comments)"} too. > > In the help I found this line: > > in[]: StringCases["-(a)--(bb)--(c)-", Shortest["(" ~~ __ ~~ ")"]] > out: {"(a)","(bb)","(c)"} > > which, at first sight, works as I desire. > > But when I add bracket at start of line then answer is incorrect > in[]: StringCases["(-(a)--(bb)--(c)-", Shortest["(" ~~ __ ~~ ")"]] > out: {"(-(a)","(bb)","(c)"} > > What is wrong? And how to solve this problem? >