Given a string such as
September 3 September 3 September 2 September 1 September 10 August 14
I want to have an output of
September 03 September 03 September 02 September 01 September 10 August 14
Tried some regular expressions with no luck :/
You could try finding only numbers which are single digit ones. Then you can replace them with themselves preceded by zero. Your code can look like
I used lookaroud mechanisms
(?<!\\d)
(?!\\d)
to make sure that digit we find\d
has no other digits before or after.Replacement
0$0
contains0
literal and$0
which is reference to group 0 - match found by our regex.But if you are responsible for generating this text
from smaller parts
September 3
September 3
September 2
September 1
September 10
August 14
then maybe consider using String formatter to create this parts with this additional0
likeHope below Snippet helps. This is a quick and dirty solution though :)
use this simple pattern
and replace w/
Demo