Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

StringCases and Shortest

  • To: mathgroup at smc.vnet.net
  • Subject: [mg97353] StringCases and Shortest
  • From: Grischika at mail.ru
  • Date: Wed, 11 Mar 2009 04:26:42 -0500 (EST)

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