I've read about limitation, but is it a way to compose regex without big time penalty?
I tried smth like /$regex*$regex*$regex*/ if I wanted match up to 96000 times, but it takes a lot of time regex to finish. | [reply] |
$ perl -e '$s="(\\d\\w)" x 3; $X="a1b2c3d4e5"; $m=qr/$s/; @R=$X=~$m;
+print join(";",@R)."\n"'
1b;2c;3d
another way could be divide and conquer. Paying a penalty by using $' (the rest of the string that has not matched yet) for the next iteration. another idea is using index | [reply] [d/l] |
caveat about the multiplier: It assumes you can match that amount, so if you have 10 patterns to find, but matching 3 at a time, you are unable to match the last one.
| [reply] |
I had a input line of 100k characters '0' or '1'. I tried to solve a problem and find length of alternating subsequence. My approach was
() = $line =~ /(.)\1*/g
When I got test-case '0' x 100k, I gain answer of 4, not 1. Because (I think) it found three matches of length 32678 and the rest shorter match.
When I used
() = $line =~ /(.)\1*\1*\1*\1*/g
- it worked slower on test case '01' x 50k. But I can't say how slower, because it was only a part of program (maybe not hot point). | [reply] [d/l] [select] |
if I wanted match up to 96000 times,
What's your application?
With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
In the absence of evidence, opinion is indistinguishable from prejudice.
| [reply] |
"... if I wanted match up to 96000 times ..."
You're fired.
| [reply] |