solution_122y.py

#!/usr/bin/python3
# ====================================================================
# test searching for md tags, etc.
# ====================================================================

import re       

REGX01 = re.compile(r"(__"
                    r"|//"
                    r"|\*\*"
                    r"|\\\\$"
                    r"|\\\\\s"
                    r"|##"
                    r"|#)")

teststr = r'__abc**def**ghi\\ j__kl//mno__pqr\\xyz\\'

# --------------------------------------------------------------------
# ---- search for MD tags
# --------------------------------------------------------------------

def search_for_md(line,lst):

    while True:

        print()
        print(f'searching "{line}"')

        res = re.search(REGX01,line)

        # ---- end of string?
    
        if not res:
            print(f'res = {res}')
            print('end search')
            break
        
        # ---- get md tag

        start = res.start()
        end   = res.end()
        tag = res.groups()[0]
              
        print(f'start={start}, end={end}, tag-found="{tag}"')

        line = line[end:]

# --------------------------------------------------------------------
# ---- main
# --------------------------------------------------------------------

lst  = []

search_for_md(teststr,lst)