[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: String Index
From: |
Mike Miller |
Subject: |
Re: String Index |
Date: |
Mon, 27 Jun 2016 09:10:56 -0700 |
User-agent: |
Mutt/1.6.0 (2016-04-01) |
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.
--
mike