Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[REGEXP] Why is this so slow

5 views
Skip to first unread message

Michael Robbins

unread,
Jul 27, 2005, 12:50:26 PM7/27/05
to
I'm planning on rewriting it, but it is so nice... if it weren't so
slow! Any ideas before I do?

% SEPARATE THE FUNCTIONS
regex = [
'(?<=\n\s*)' ...
'(?<prename>' ...
'function\s+' ...
'(?:\[[^\]]*\s*=\s*)?' ...
')' ...
'(?<name>\w+)' ...
'(?<postname>.*?)' ...
'(?=\n\s*function\s+)'];
a = regexp(sprintf('\n%s\nfunction ',slurp),regex,'names');

TIA

Jason Breslau

unread,
Jul 27, 2005, 3:15:07 PM7/27/05
to
The current implementation of lookbehind in regexp is rather
inefficient. Avoid using it if possible. Your pattern will work fine
with that part of the expression converted to a regular group.

-=>J

Michael Robbins

unread,
Jul 27, 2005, 4:57:51 PM7/27/05
to
Jason Breslau wrote:
>
>
> The current implementation of lookbehind in regexp is rather
> inefficient. Avoid using it if possible. Your pattern will work
> fine
> with that part of the expression converted to a regular group.

Thanks. I converted the regex and it works well now, though still a
little slow. It turns out there was a small bug in the one I posted
anyway.

BTW, I'm really happy with the features you've put into REGEXP. I
never understood why you wanted to reinvent the wheel but you
certainly did a good job. MATLAB is far better for it.

It'd be really great if you continued to proliferate REGEXP
throughout MATLAB and the IDE.

0 new messages