in reply to Regexp: How to match in middle but not the ends?

Perhaps you should read perlre and see if a non-greedy modifier /[CSH][CSHL]+?/ helps? Or explicitly require that the last character isn't an L, /[CSH][CSHL]*[CSH]/g.

Replies are listed 'Best First'.
Re^2: Regexp: How to match in middle but not the ends?
by ikegami (Patriarch) on Jul 28, 2006 at 20:39 UTC

    /[CSH][CSHL]+?/ doesn't work. It would incorrectly match "CL" in "---CL---", and it will never match more than two characters.

    /[CSH][CSHL]*[CSH]/ works.

    If there wasn't a two character minimum, we'd have to use zero-width lookaheads and/or lookbehinds.