in reply to Regex Question

This might be easiest:

$field =~ s/((.)(?:\\|\/)(.))/ if ($2 eq 'C' && $3 eq 'O') { $1 } elsif (ord($2) >= ord('0') && ord($2) <= ord('9')) { $1 } elsif (ord($3) >= ord('0') && ord($3) <= ord('9')) { $1 } else { "$2 & $3" } /xeg;

Update: I had a "==" where I needed a "eq". Also fixed the problem Roy found.

Replies are listed 'Best First'.
Re^2: Regex Question
by Aristotle (Chancellor) on Nov 15, 2005 at 20:02 UTC

    That will only match slashes surrounded by a character on both sides. (?!\d) is not the same as \D.

    Makeshifts last the longest.

      And it won't work when there are multiple slashes in a row. Only some of them will get converted. Sorry, I meant to mention the caveats. I knew about them, but I thought they might be acceptable to the OP.
Re^2: Regex Question
by Roy Johnson (Monsignor) on Nov 15, 2005 at 20:16 UTC
    Update: if ($1 eq 'C' && $2 eq 'O') should be if ($2 eq 'C' && $3 eq 'O'), because $1 is the entire matched expression.

    Caution: Contents may have been coded under pressure.