Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Matching Character Phrases...
Date: Thu, 21 Feb 2008 22:24:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 25
Message-ID: <fpktm4$501$1@fred.mathworks.com>
References: <fpkn42$3cg$1@fred.mathworks.com> <fpkp21$rvm$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1203632644 5121 172.30.248.38 (21 Feb 2008 22:24:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 21 Feb 2008 22:24:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1138100
Xref: news.mathworks.com comp.soft-sys.matlab:453014



"jay vaughan" <jvaughan5.nospam@gmail.com> wrote in message 
<fpkp21$rvm$1@fred.mathworks.com>...
> I recently learned a little about regexp, and you might try 
> something like the following. You could use the 
> outputs 'num_times' and 'distances' to format the output 
> exactly how you want it. No loop required.
> 
> J
> 
> A = 'OPASKSGLBOJASLOPASNKMGLBOSDLASJSFLOPASHHASKSMLGLBO';
> user_str = 'OPAS';
> [s] = regexp(A,user_str,'start');
> num_times = size(s,2);
> distances = diff(s);
> 


Thanks for your help, that's definitely along the right lines, although I need 
the program to be finding the phrases itself.  So, for example, it firstly tries to 
find all 'OPAS' matches in 'text' (A, in your example), then moves on to 'PASK' 
matches, then 'ASKS' etc, until it has found 30 matches, or it reaches the end 
of the 'text'.