I was wondering how one would go about changing the first digit (0-9) that comes after a capital letter (A-Z) in a string to an asterisk WITHOUT using sub. You can put this in a method called replace_digit if you want.
I was wondering how one would go about changing the first digit (0-9) that
Share
No
sub🙂EDIT: I just noticed “first digit” – so just remove the loop; and if you can assume there will always be a match, you can remove the exception handling too.
EDIT2:
this works too, without lookbehind:
a[/[A-Z](\d)/, 1] = "*"