From: Janus Bor Date: 2008-08-16T10:56:26+09:00 Subject: [Regex] Alternative for look behind Hi all, I need to replace all '-' characters at the beginning of a sequence (string) with 'X's (until a character appears that is not '-'). E.g. -------abcde-gh---- should be changed into XXXXXXXabcde-gh---- If Ruby would support look behind in Regular Expressions, I could probably do something like this: sequence.gsub(/(?=^-*)-/, "X") But unfortunately Ruby does not support look behind. Of course, I could count the number of '-' at the beginning of the sequence: x = sequence[/-*/].length And then I could replace the first x characters with "X". But I don't like that solution, it feels clumsy. Is there an elegant way of doing this? Thanks in advance & best regards! Janus -- Posted via http://www.ruby-forum.com/.