in reply to Regex, loops and subs

Try replacing all the match-everything dots in your regular expressions by negative character classes. So for example, instead of

m/^.+?:.+?\. (.+)+$/
do
m/^[^:]+:[^.]+\. (.+)$/

(what's with the plus-sign at the end anyway, you're basically saying "match one or many of any character one or many times"?)


Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

Replies are listed 'Best First'.
Re^2: Regex, loops and subs
by Hena (Friar) on Nov 15, 2005 at 11:15 UTC
    Is the negative character class faster? I had it before, but thought that using '.' would be slightly faster (though some times this feels like micro optimisation). Since its not a user defined list as such. It might be easier to read though.

      Yes, because it avoids the useless look-aheads and backtracks on failed matches.


      Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan