What's the speed that blocks regenerate from being hit?
Per the wiki on breaking, there isn't a regeneration speed, only a digging speed:
The player's digging speed is controlled by three factors: the block being broken, the item the player is currently wielding, and the mining penalties affecting the player.
The regeneration you see is purely visual effect.
Overall, this is a simple but variable heavy calculation, and the wiki does a fantastic job on explaining each piece to the digging speed puzzle. For your convenience, I've brought over their pseudocode for calculating the digging speed:
if (isBestTool): speedMultiplier = toolMultiplier if (not canHarvest): speedMultiplier = 1 else if (toolEfficiency): speedMultiplier += efficiencyLevel ^ 2 + 1 if (hasteEffect): speedMultiplier *= 1 + (0.2 * hasteLevel) if (miningFatigue): switch (miningFatigueLevel): case 0: speedMultiplier *= 0.3 case 1: speedMultiplier *= 0.09 case 2: speedMultiplier *= 0.0027 default: speedMultiplier *= 0.00081 if (inWater and not hasAquaAffinity): speedMultiplier /= 5 if (not onGround): speedMultiplier /= 5 damage = speedMultiplier / blockHardness if (canHarvest): damage /= 30 else: damage /= 100 # Instant breaking if (damage > 1): return 0 ticks = roundup(1 / damage) seconds = ticks / 20 return seconds
All of the information you need to populate the variables is available through the aforementioned wiki.
Visually - after 20s.
The block "heals" instantaneously if you release the 'attack' button while damaging it, or aim at a different block. But if you keep holding attack, but the distance between you and the targeted block increases enough that it gets out of range, the breaking progress is frozen. It doesn't revert/heal over time, and if you close the distance to resume breaking, it will be resumed at the point you left it off.
Additionally, releasing the mouse key leaves the block in visually "partially broken" state. At that point you can't resume it, as left-clicking any block (including the "partially broken" one) resets the progress to zero.
The blocks left in the "partially broken" state visually revert to 'undamaged' appearance after 20 seconds since damage was applied last, but if you didn't release attack in the meantime and didn't target any other block with your attack, you can still resume breaking from where you left off.
This breaking style is most frequently encountered when chopping down birch and spruce trees - if the tallest block is off your reach when standing on the ground, you can jump and break it eventually in several jumps, despite it coming out of your range as you land between the jumps.