help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: String Index


From: Thomas D. Dean
Subject: Re: String Index
Date: Mon, 27 Jun 2016 10:56:52 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0

On 06/27/2016 09:10 AM, Mike Miller wrote:
On Mon, Jun 27, 2016 at 08:43:40 -0700, Thomas D. Dean wrote:
I played with regexp() some, but, could not find a pattern that matched just
the characters within the parens.

str

str = "_units_           (10^15 kg)         (km)          (kg/m^3)   "
[s, e, te, m, t, nm, sp] = regexp(str,"\(...\){3,5}");m
m
m =
{
   [1,1] = _units_
   [1,2] =    (10^15 kg)
   [1,3] =        (km)
   [1,4] =       (kg/m^3)

}

is close, but, still needs some parsing.  Most likely not better than using
strtok.

Sorry, but that regex is not actually doing anything like what you want.

First, single vs double quoting is important when using backslashes in
strings. Backslashes in double quoted strings are interpreted by the
parser. So your quoted string above is the same as '(...){3,5}'.

Second, this regex means "find 3 to 5 groups of any 3 characters". And
sure enough, if you look at the sizes of each of the strings in m, they
are each 15 characters long.


Half-hour reading "sed & awk", I found something that is closer.

> str = "_units_           (10^15 kg)         (km)          (kg/m^3)   "
> [s, e, te, m, t, nm, sp] = regexp(str,'\([0-9a-zA-Z][^(]*');m
m =
{
  [1,1] = (10^15 kg)
  [1,2] = (km)
  [1,3] = (kg/m^3)
}

Tom Dean



reply via email to

[Prev in Thread] Current Thread [Next in Thread]