I have text that occasionally substitutes an l or I for a 1 (it’s from OCR). I want to convert these to a 1 when they are part of a number, but leave them alone if they stand alone. By “part of a number” I mean adjacent to another digit or l or I. So I want to change 1I3 to 113 but leave 1 I 3 alone.
Here’s what I’m doing:
$var =~ s/[lI](?=[lI\d])/1/g;
$var =~ s/(?<=[lI\d])[lI]/1/g;
Is there a more elegant way to do this in one step? In other words, what regex will match [Il] that is either preceded by [lI\d] or followed by [lI\d]?
You can use the alternation metacharacter
|:Poor Kim Jong 11, though.