Adding Numbers with Regex I want to try a new type of regex golf challenge, which asks you to solve nontrivial computational tasks with nothing but regex substitution. To make this more possible and less of a chore, you will be allowed to apply several substitutions, one after the other.

The Challenge

We'll start simple: given a string containing two positive integers, as decimal numbers separated by a ,, produce a string containing their sum, also as as a decimal number. So, very simply

47,987


should turn into

1034


Your answer should work for arbitrary positive integers.

The Format

Every answer should be a sequence of substitution steps, each step consisting of a regex and a replacement string. Optionally, for each of those steps in the sequence, you may choose to repeat the substitution until the string stops changing. Here is an example submission (which does not solve the above problem):

Regex    Modifiers   Replacement   Repeat?
\b(\d)   g           |$1           No
|\d      &lt;none&gt;      1|            Yes
\D       g           &lt;empty&gt;       No


Given the input 123,456, this submission would process the input as follows: the first substitution is applied once and yields:

|123,|456


Now the second substitution is applied in a loop until the string stops changing:

1|23,|456
11|3,|456
111|,|456
111|,1|56
111|,11|6
111|,111|


And lastly, the third substitution is applied once:

111111


Note that the termination criterion for loops is whether the string changes, not whether the regex found a match. (That is, it might also terminate if you find a match but the replacement is identical to the match.)

Scoring

Your primary score will be the number of substitution steps in your submission. Every repeated substitution will count for 10 steps. So the above example would score 1 + 10 + 1 = 12.

In the (not too unlikely) case of a tie, the secondary score is the sum of the sizes of all steps. For each step add the regex (without delimiters), the modifiers and the substitution string. For the above example this would be (6 + 1 + 3) + (3 + 0 + 2) + (2 + 1 + 0) = 18.

Miscellaneous Rules

You may use any regex flavour (which you should indicate), but all steps must use the same flavour. Furthermore, you must not use any features of the flavour's host language, like replacement callbacks or Perl's e modifier, which evaluates Perl code. All manipulation must happen exclusively through regex substitution.

Note that it depends on your flavour and modifiers whether each single replacement replaces all occurrences or only a single one. E.g. if you choose the ECMAScript flavour, a single step will by default only replace one occurrence, unless you use the g modifier. On the other hand, if you're using the .NET flavour, each step will always replace all occurrences.

For languages which have different substitution methods for single and global replacement (e.g. Ruby's sub vs. gsub), assume that single replacement is the default and treat global replacement like a g modifier.

Testing

If your chosen flavour is either .NET or ECMAScript, you can use Retina to test your submission (I'm being told, it works on Mono, too). For other flavours, you will probably have to write a small program in the host language which applies the substitutions in order. If you do, please include this test program in your answer.
.NET flavor, score:2
Regex        Modifiers  Replacement  Repeat?
&lt;empty&gt;      &lt;none&gt;     9876543210   No
&lt;see below&gt;  x          &lt;empty&gt;      No

I'm not bothered to golf it yet, and x is just for ignoring whitespaces.
It firstly insert 9876543210 at each position, then delete the original characters and the characters those are not the current digit of the sum.
The big regex (1346 bytes without whitespaces and comments):
# If the length of the left number &lt;= right number, delete every digit on the left.
.(?=.*,(?&lt;=^(?&lt;len&gt;.)*,)(?&lt;-len&gt;.)*(?(len)(?!)))|

# Do the opposite if it is not the case.
.(?&lt;=(?(len)(?!))(?&lt;-len&gt;.)*(?=(?&lt;len&gt;.)*$),.*)|

# Remove leading zeros.
(?&lt;=(^|,).{9})0|

# Delete everything that is not the current digit of the sum.
.(?!
    # For digits in the left part:
    (?&lt;cur&gt;.){0,9}               # cur = the matched digit
    (?=(.{11})*,)                # and find the position before the next digit.
    (?&lt;first&gt;)                   # first = true
    (                            # Loop on the less significant digits:
        (?&lt;cur&gt;){10}             # cur += 10
        (?&lt;=                     # cur -= the current digit in this number.
            (
                0|^|
                1(?&lt;-cur&gt;)|
                2(?&lt;-cur&gt;){2}|
                3(?&lt;-cur&gt;){3}|
                4(?&lt;-cur&gt;){4}|
                5(?&lt;-cur&gt;){5}|
                6(?&lt;-cur&gt;){6}|
                7(?&lt;-cur&gt;){7}|
                8(?&lt;-cur&gt;){8}|
                9(?&lt;-cur&gt;){9}
            )
            .{10}
        )
        (?=
            (?&lt;pos&gt;.{11})*,      # pos = which digit it is.
            .*$(?&lt;=              # cur -= the current digit in the other number.
                (
                    0|,|
                    1(?&lt;-cur&gt;)|
                    2(?&lt;-cur&gt;){2}|
                    3(?&lt;-cur&gt;){3}|
                    4(?&lt;-cur&gt;){4}|
                    5(?&lt;-cur&gt;){5}|
                    6(?&lt;-cur&gt;){6}|
                    7(?&lt;-cur&gt;){7}|
                    8(?&lt;-cur&gt;){8}|
                    9(?&lt;-cur&gt;){9}
                )
                .{10}
                (?(pos)(?!))     # Assert pos = 0.
                                 # Skip pos input digits from the end.
                                 # But stop and set pos = 0 if the comma is encountered.
                ((?&lt;-pos&gt;\d{11})|(?&lt;=(?&gt;(?&lt;-pos&gt;.)*),.{10}))*
            )
        )
        (?(first)                # If first:
            (?&gt;((?&lt;-cur&gt;){10})?) #  cur -= 10 in case there is no carry.
                                 #  Assert cur = 0 or 1, and if cur = 1, set cur = 10 as carry.
            (?(cur)(?&lt;-cur&gt;)(?(cur)(?!))(?&lt;cur&gt;){10})
            (?&lt;-first&gt;)          #  first = false
        |                        # Else:
                                 #  cur is 10 or 20 at the beginning of an iteration.
                                 #  It must be 1 to 11 to make the equation satisfiable.
            (?&lt;-cur&gt;)            #  cur -= 1
            (?(cur)              #  If cur &gt; 0:
                                 #   cur -= max(cur, 9)
                (?(cur)(?&lt;-cur&gt;)){9}
                (?(cur)          #   If cur &gt; 0:
                                 #    Assert cur = 1 (was 11) and set cur = 10.
                    (?&lt;-cur&gt;)(?(cur)(?!))(?&lt;cur&gt;){10}
                |                #   Else:
                    .*(?=,)      #    cur was 2 to 10, break from the loop.
                )
            )                    #  Else cur is 0 (was 1) and do nothing.
        )
        (.{11}|,)                # Jump to the next digit.
    )*(?&lt;=,)(?(cur)(?!))         # End the loop if it is the last digit, and assert cur = 0.
|
    # Do the same to the right part. So the sum will be calculated two times.
    # Both are truncated to the original length of the number on that side + 1.
    # Only the sum on the longer side will be preserved in the result.
    (?&lt;cur&gt;\d){0,9}
    (?=(\d{11})*$)
    (?&lt;first&gt;)
    (
        (?&lt;cur&gt;){10}
        (?&lt;=
            (
                0|,|
                1(?&lt;-cur&gt;)|
                2(?&lt;-cur&gt;){2}|
                3(?&lt;-cur&gt;){3}|
                4(?&lt;-cur&gt;){4}|
                5(?&lt;-cur&gt;){5}|
                6(?&lt;-cur&gt;){6}|
                7(?&lt;-cur&gt;){7}|
                8(?&lt;-cur&gt;){8}|
                9(?&lt;-cur&gt;){9}
            )
            .{10}
        )
        (?=
            (?&lt;pos&gt;.{11})*$
            (?&lt;=
                (
                    0|^|
                    1(?&lt;-cur&gt;)|
                    2(?&lt;-cur&gt;){2}|
                    3(?&lt;-cur&gt;){3}|
                    4(?&lt;-cur&gt;){4}|
                    5(?&lt;-cur&gt;){5}|
                    6(?&lt;-cur&gt;){6}|
                    7(?&lt;-cur&gt;){7}|
                    8(?&lt;-cur&gt;){8}|
                    9(?&lt;-cur&gt;){9}
                )
                .{10}
                (?(pos)(?!))
                ((?&lt;-pos&gt;\d{11})|(?&lt;=^.{10})(?=(?&gt;(?&lt;-pos&gt;.)*)))*
                ,.*
            )
        )
        (?(first)
            (?&gt;((?&lt;-cur&gt;){10})?)
            (?(cur)(?&lt;-cur&gt;)(?(cur)(?!))(?&lt;cur&gt;){10})
            (?&lt;-first&gt;)
        |
            (?&lt;-cur&gt;)
            (?(cur)
                (?(cur)(?&lt;-cur&gt;)){9}
                (?(cur)
                    (?&lt;-cur&gt;)(?(cur)(?!))(?&lt;cur&gt;){10}
                |
                    .*$(?&lt;end&gt;)
                )
            )
        )
        (.{11}|$(?&lt;end&gt;))
    )*(?&lt;-end&gt;)(?(cur)(?!))
)

This made me think of the final level of Manufactoria... But I think .NET regex, which is obviously no longer &quot;regular&quot;, can solve any problems in PH. And this is just an algorithm in L.