I want to put two spaces before every number in a document, is there a way to automate this?

Im hoping theres some kind of scripting language or something similar, I want to be able to say

‘if a line begins with a number;
put two spaces at the beginning of the line’

Usually, a line beginning with a number is some kind of numbered list, where the number monotonically increases without “holes”. If this is the case, styling the paragraph as a list will automatically number it and playing with the style settings you can achieve your decoration. Better, instead of inserting spaces which length may be changed by justification, you can indent the list resulting in fixed spacing aligning all numbers on the same vertical reference line.

Edit your question if you need help in this direction. Don’t use an answer.

You can used find and replace with regular expressions

If you preferred by code, try:

def add_space():
    doc = XSCRIPTCONTEXT.getDocument()
    for line in doc.Text:
        if line.String[0].isdigit():
            line.String = '  ' + line.String
    return

Perhaps you should mentioned the code type (Python, Basic …)