in reply to Re: Very slow regex substitution on Unicode string
in thread Very slow regex substitution on Unicode string

There is not so much backtracking going on I think.

I need to delete the whole xml-comment when it starts with the space+HINT. I think the fastest way is:

s/<!-- HINT.*? -->//
The ".*?" should do minimal matching, i.e. stopping as soon as the string-so-far is followed by the litteral space-dash-dash-greaterthan. This (should) makes it do no backtracking at all, I believe. I do not think I can make it faster, or am I wrong?

Also the removal of the initial BOM should not lead to much backtracking. The regex engine should look at most at one character ahead in this case (I think).

s/^\x{feff}*//
And note that the whole regex was anchored at the beginning of the string too; again leading to much less work.

I'll just wait for CentOS 6.x to come out, which has perl5.10, and until then just split up the regex. Good enough for me.

Replies are listed 'Best First'.
Re^3: Very slow regex substitution on Unicode string
by Anonymous Monk on May 26, 2011 at 15:11 UTC
    You should get minimal backtracking. At the start of each word in the comment it will backtrack over the space between words.

    You should look into building your own up-to-date perl. I've found it to be remarkably easy on both Solaris & Linux boxes, and you get to use the latest & greatest perl for you own work. Just leave the system version where it is, and put your own on the #! line of your programs or put it earlier in your personal PATH.

    TJD