function [start,finish]=regexp(str,expr) // Match regular expressions in strings. // str - string to be processed. // expr - regular expression to be identified in str // start - index to start of each matching expr in str. // finish - index to end of each matching expr in str. // Description // regexp idetifies the start and finish of each matching // regular expression in a string. // regexp requires that perl is installed and available through the path. // // Unforturnately regexp.sci has not been adapted to work in an // Windows/MSDOS environment, but this only requires minor // modifications to the source code. // // Examples: // str='bat cat can car coat court cut ct caoueaouat'; // pat = 'c[aeiou]+t'; // [s,f]=regexp(str,pat) // [s,f]=regexp('regexp helps you relax','\w*x\w*') // Copyright (C) 2003 Torbjørn Pettersen. // $Id: regexp.sci,v 1.3 2003/11/04 18:12:09 top Exp $ // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA if MSDOS, x_message(['regexp.sci only works in linux/unix environments currently',... 'You only need to modify the code slightly to work under Windows.']) end // A nice selfexplaining perl program does the jobb :-) pl = "... $_=shift; $e=shift; ... while($_) { ... if (/($e)/) { ... push(@tok,$1); ... push(@st,index($_,$1)+1); ... ($foo,$_)=split($e,$_,2); ... } else { $_='''';}; ... }; ... @fin=@st; @fin[0]=@fin[0]+length(@tok[0])-1; ... for $i (1..$#st) { ... @st[$i]=@st[$i-1]-1+@st[$i]+length(@tok[$i-1]); ... @fin[$i]=@st[$i]+length(@tok[$i])-1; ... }; ... print ""{["".join('';'',@st).""],["".join('';'',@fin).""]}\n"";"; u=file('open',TMPDIR+'/regexp.pl','unknown'); write(u,pl); // write down the perl program file('close',u); // Run perl program and evaluate the output from the program. res=evstr(... unix_g("perl "+TMPDIR+"/regexp.pl "+sprintf(' ''%s'' ''%s''',str,expr))); start=res(:,1); finish=res(:,2);