Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!newsfeed.stanford.edu!elk.ncren.net!newsflash.concordia.ca!canopus.cc.umanitoba.ca!not-for-mail
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Newsgroups: comp.soft-sys.matlab
Subject: Re: simple regexp question
Date: Tue, 12 Aug 2008 16:30:22 +0000 (UTC)
Organization: National Research Council Canada - Conseil national de rechereches Canada
Lines: 35
Message-ID: <g7sdqu$jif$1@canopus.cc.umanitoba.ca>
References: <g7scqd$lbp$1@fred.mathworks.com>
NNTP-Posting-Host: origin.ibd.nrc.ca
X-Trace: canopus.cc.umanitoba.ca 1218558622 20047 192.70.172.160 (12 Aug 2008 16:30:22 GMT)
X-Complaints-To: abuse@cc.umanitoba.ca
NNTP-Posting-Date: Tue, 12 Aug 2008 16:30:22 +0000 (UTC)
Originator: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Xref: news.mathworks.com comp.soft-sys.matlab:485082



In article <g7scqd$lbp$1@fred.mathworks.com>, matt dash <n.a@mail.com> wrote:

>I have a cell array of strings, each of which looks like :

>'Lambda46' => '54.954684760469313', 

>(including the quotes and comma) and I want to extract the
>two numbers 46 and 54.954... and put them in vectors.
>Normally I would do this by finding the locations of the
>quotes and working from there, but I suspect there's a
>better way using regular expressions and I figure it's about
>time I started using them... is there a simple way to do this?

You don't quite give enough information about the form of the
numbers, and you don't give us any information about whether
there can be digits in the identifier before the trailing digits
that you want to extract (e.g., 'Rom3Gam17')

(\d+).*((?:\d+(?:\.\d*))|(?:\.\d+))

The above expression assumes that the two set of digits
on the line are to be extracted. It allows three forms
for the second number: an integer with no decimal place;
or a fixed-point number with digits followed by decimal point
optionally followed by digits; or a fixed-point number that starts
immediately with a decimal point followed by {mandatory} digits.
It does not allow the second "number" to consistent entirely of
a decimal point with no digits. The complexity of the expression
could potentially be much reduced if it was known that some
of these forms never occur.
-- 
  "What is important, then, is not that the critic should possess a
  correct abstract definition of beauty for the intellect, but a
  certain kind of temperament, the power of being deeply moved by
  the presence of beautiful objects."         -- Walter Pater