From: dpb on
Greg Thom wrote:
....

> The problem I have is that Pt1,Val1,...,PtN,ValN is variable (N = Numpts
> for a each line) so I need to dynamically modify the regexp as I go
> using the value I capture with Numpts. Now I can capture the value no
> problem.
....

> Does anyone know how to write this properly, I have tried but failed in
> make repmat execute during regexp execution.
....

I "know nuthink" (in any depth, at least) of regexp and absolutely
nothing of the dialect in later versions of ML so I'll venture forth with--

Why not do a two pass-solution? Get the number, build/rebuild the parse
expression and give a second go w/ that...

--
From: Jason Breslau on
A limitation of the current implementation of regexp is that dynamic
patterns may not capture tokens.

-=>J
From: Walter Roberson on
Greg Thom wrote:

> Because I have that format I need to repmat it Numpts times during
> regexp execution to capture all Pt1,Val1,...,PtN,ValN. eg for str1 I
> need to repmat('\d,\[-+]?[0-9]*\.?[0-9]+',1,Numpts)
> or using regexp
> (??@repmat('\d,\[-+]?[0-9]*\.?[0-9]+',1,$2)) % NumPts has been captured
> in token #2.


Because you want the Pt to be separated from the Val, you want () around the
distinct parts. And you've let a \ creep in before the [-+] which would cause
it to look for literal [ characters . And if there is no decimal point, then
the [0-9]+ at the end, being forced to match one character at least, is going
to force the [0-9]* (which would have matched the entire number) to "back up"
by one position, which is inefficient. You also haven't allowed for the comma
after the Val when you did the repmat. [0-9] is shorter as \d . And since this
is presumably within a quoted string, you have to double the ' in order not to
end the overall string when you start the string you want to repmat.

Also, below I won't assume that NumPts is at most 9:

(??@repmat(''(\d+),([-+]?\d*\.?\d*),'', 1, $2))

There is a _possibility_ that you might have to double the \ but I suspect
not... well, maybe in some circumstances in front of digits or token names.
From: Greg Thom on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hogaes$sp$1(a)canopus.cc.umanitoba.ca>...
> Greg Thom wrote:
>
> > Because I have that format I need to repmat it Numpts times during
> > regexp execution to capture all Pt1,Val1,...,PtN,ValN. eg for str1 I
> > need to repmat('\d,\[-+]?[0-9]*\.?[0-9]+',1,Numpts)
> > or using regexp
> > (??@repmat('\d,\[-+]?[0-9]*\.?[0-9]+',1,$2)) % NumPts has been captured
> > in token #2.
>
>
> Because you want the Pt to be separated from the Val, you want () around the
> distinct parts. And you've let a \ creep in before the [-+] which would cause
> it to look for literal [ characters . And if there is no decimal point, then
> the [0-9]+ at the end, being forced to match one character at least, is going
> to force the [0-9]* (which would have matched the entire number) to "back up"
> by one position, which is inefficient. You also haven't allowed for the comma
> after the Val when you did the repmat. [0-9] is shorter as \d . And since this
> is presumably within a quoted string, you have to double the ' in order not to
> end the overall string when you start the string you want to repmat.
>
> Also, below I won't assume that NumPts is at most 9:
>
> (??@repmat(''(\d+),([-+]?\d*\.?\d*),'', 1, $2))
>
> There is a _possibility_ that you might have to double the \ but I suspect
> not... well, maybe in some circumstances in front of digits or token names.


Hello all, thanks for the suggestions, I don't know but I thought regexp can solve this problem especially with the dynamic regexp so I tried walter's suggestion

>> [toks mat] = regexp(str1,'Test-Results: ,\w*>\w*,,,(\d+),(??@repmat(''(\d+),([-+]?\d*\.?\d*),'', 1, $1))3,','tokens')
??? Error using ==> regexp
Evaluation of 'repmat('(\d+),([-+]?\d*\.?\d*),', 1, $1)' did not produce a string.

The trick is to get repmat to evaluate properly and produce the right string for ??@ to accept.

Anyone ?

Cheers
From: us on
"Greg Thom"
> but can anyone explain why is it returning empty , I know for sure that the repmat is executing correctly , what I don't know is what the final regexp expression looks like, is there anyway to debug and view the actuall regexp string that is executing ?

why insisting on REGEXP(?)...
you were shown another solutions, which gets you started right away without wasting any more time...

us
 |  Next  |  Last
Pages: 1 2
Prev: fmincon and Hessian
Next: Concatenate from a for loop