[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: regexp: matching expressions b4 and after ....
From: |
Ben Abbott |
Subject: |
Re: regexp: matching expressions b4 and after .... |
Date: |
Mon, 08 Sep 2008 12:22:27 -0400 |
On Monday, September 08, 2008, at 11:38AM, <address@hidden> wrote:
>Hi,
>
>I'm trying to convert a set of matlab codes into Octave. These codes heavily
>use string manipulation functions
>
>In particular I'm trying to extract a set of equations from an ASCII file.
>From these equations I extract/replace variables etc.
>
>So, for example, I have g="x^(-1)+y(-1)+z(-1)=0"
>
>I need to extract/replace x, y and (-1). So, for example, I used the command
>regexprep(g,'(?<=[a-z]*)\(\-[1-9]*\)','\_minus1')
>
>which returned "x^(-1)+y_minus1+z_minus1"
>
>Can I do the same in Octave? How?
>
Doesn't work for me either
octave:1> g="x^(-1)+y(-1)+z(-1)=0"
g = x^(-1)+y(-1)+z(-1)=0
octave:2>
octave:2> regexprep(g,'(?<=[a-z]*)\(\-[1-9]*\)','\_minus1')
error: syntax error in pattern
Running Matlab2007b
>> g='x^(-1)+y(-1)+z(-1)=0';
>> regexprep(g,'(?<=[a-z]*)\(\-[1-9]*\)','\_minus1')
ans =
x^_minus1+y_minus1+z_minus1=0
I'd suggest you try to isolate the error. Perhaps if the developers knew where
the specific problem was they could fix it.
I'm not experienced with regexp, but the simpler one below works for your
example.
regexprep(g,'\(\-[1-9]*\)','_minus1')
ans = x^_minus1+y_minus1+z_minus1=0
Ben