MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

StringCases and Shortest


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?


  • Prev by Date: Slicing a surface
  • Next by Date: Re: about mathlink connection
  • Previous by thread: Re: Slicing a surface
  • Next by thread: Re: StringCases and Shortest