#rs, 107 bytes
rs, 107 bytes
\t/ (?<!\\)((\*|_){2})((?=\S)(?!\2)(\\\2|.)*?)?(?<=\S)\1/(\n)^^((^^\3))\3 \\(\*|_)/\t [^\t\n]/ \n/_ \t_?/ (_*)/(^^\1) This is a pretty crazy...thing.
The newest test case does not work yet. WIP...
##Explanation
Explanation
\t/ Replace tabs with spaces. They have the same character count, and tabs are used later on as a special character.
(?<!\\)((\*|_){2})((?=\S)(?!\2)(\\\2|.)*?)?(?<=\S)\1/(\n)^^((^^\3))\3 Replace any text of length N that should be bolded with N newlines followed by the original text.
\\(\*|_)/\t Replace any occurrences of a delimiter immediately preceded by a slash with a tab. This is to make sure that entries like **a\*** have a character count of 2 instead of 3.
[^\t\n]/ Remove any character that's not a tab or newline.
\n/_ Replace all the newlines with underscores.
\t_?/ Remove any tabs (which represent escaped delimiters), along with any underscores that may follow them. This is related to the above issue of character counts with escaped ending delimiters.
(_*)/(^^\1) Replace the underscore sequence with its length. This is the character count.