in reply to Re^2: Regex Question
in thread Regex Question

That won’t match the exact same things. The OP’s regex will replace the slash in "/2" or in "1/", yours won’t. Not sure if this is part of the spec, but it’s something to be aware of.

Meh. That’s it, I’m going back to bed.

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^4: Regex Question
by Roy Johnson (Monsignor) on Nov 15, 2005 at 20:23 UTC
    Mine does replace the slash when it has a digit on only one side. The logic is that the slash is replaced unless there is a digit on both sides. It is the OP's logic that will not replace a slash with a digit on either side.
    for my $field ( map $_, 'C/O', '2/4', 'C/2', 'd/l', '2/', '/2') { print "$field..."; $field =~ s/ (?<!C(?=.O)) # Look back a character and make sure it's not C-so +mething-O from there (?<!\d(?=.\d)) # Make sure it's also not a digit-something-digit (?:\\|\/) # The something is a slash or backslash / & /xgi; print "$field\n"; }

    Caution: Contents may have been coded under pressure.
Re^4: Regex Question
by shemp (Deacon) on Nov 15, 2005 at 20:07 UTC
    Yes, that would comply with my specification of the problem. If there is only a digit on one side, replace the slash with an ampersand.
    I use the most powerful debugger available: print!