I have this expression in the field calculator:
regexp_replace('2', '(\\d+)', rpad('\\1',3,'0') )
which yields '02' rather than '002' as expected
OTOH rpad('1', 3, '0')
yields '001' as expected.
Weird! Is this a bug? or am I missing something? If so I'll log something in the issue tracker.
BTW I was delighted when I found I could use complex expressions including functions in the third parameter of regexp_replace
! kudos to the QGIS developers!`