regexp: match character group or end of line

You can’t match a ^ or $ within a [] because the only characters with special meaning inside a character class are ^ (as in “everything but”) and - (as in “range”) (and the character classes). \A and \Z just don’t count as character classes.

This is for all (standard) flavours of regex, so you’re stuck with (^|[stuff]) and ($|[stuff]) (which aren’t all that bad, really).

Leave a Comment