I’m looking for a way of prepend any single digits in a string of integers and hyphens with 0. E.g.
“-0-2-3—12-0—10-” becomes “-00-02-03—12-00—10-“
or
“-12-14-7-8-” becomes “-12-13-07-08-“
I’ve tried using \d{1} with a combination of dashes but it doesn’t seem to capture all the correct parts. Any help would greatly appreciated. If a regex is too complex to do this do say, happen to write a traverser of some kind.
Thanks
If the regex engine supports lookaround assertions, then this is one way to do it:
If the regex engine doesn’t support lookbehind assertions (e.g. JavaScript), then:
If the regex engine doesn’t support lookaround assertions at all, then: