The following code doesn't extract the sections and only returns `---`.
CODE:
import re

def extract_sections(text):
    # Patterns to identify main sections and subsections
    main_section_pattern = re.compile(r'\n?((\d+))\s')
    subsection_pattern = re.compile(r'\n?\s*(([a-z]))\s')
    # You can extend patterns for deeper levels if needed

    # Find all main section matches
    main_sections = list(main_section_pattern.finditer(text))
    sections = []

    for i, match in enumerate(main_sections):
        section_number = match.group(1)
        section_start = match.end()
        if i + 1 < len(main_sections):
            section_end = main_sections[i + 1].start()
        else:
            section_end = len(text)
        section_text = text[section_start:section_end].strip()

        # Extract subsections within the main section
        subsections = []
        for sub_match in subsection_pattern.finditer(section_text):
            sub_number = sub_match.group(1)
            sub_start = sub_match.end()
            # Find next subsection or end of main section
            next_sub = subsection_pattern.search(section_text, sub_match.end())
            if next_sub:
                sub_end = next_sub.start()
            else:
                sub_end = len(section_text)
            sub_text = section_text[sub_start:sub_end].strip()
            subsections.append((sub_number, sub_text))

        sections.append((section_number, section_text, subsections))

    return sections

def format_markdown(sections):
    md = ""
    for sec_num, sec_text, subsections in sections:
        md += f"---\n\n### <strong>{sec_num}.</strong>\n"
        # Remove subsections from main section text
        if subsections:
            # Remove all subsections from the main text
            main_text = re.sub(r'\n\s*([a-z])\s.*', '', sec_text, flags=re.DOTALL).strip()
            md += f"{main_text}\n\n"
            for sub_num, sub_text in subsections:
                md += f"#### <strong>({sub_num})</strong>\n{sub_text}\n\n"
        else:
            md += f"{sec_text}\n\n"
    md += "---\n"
    return md

# Example usage
if __name__ == "__main__":
    input_text = """
(1) A company shall, 1[within thirty days of its incorporation] and at all times thereafter, have a registered office capable of receiving and acknowledging all communications and notices as may be addressed to it.
(2) The company shall furnish to the Registrar verification of its registered office within a period of thirty days of its incorporation in such manner as may be prescribed.
(3) Every company shall--
(a) paint or affix its name, and the address of its registered office, and keep the same painted or affixed, on the outside of every office or place in which its business is carried on, in a conspicuous position, in legible letters, and if the characters employed therefor are not those of the language or of one of the languages in general use in that locality, also in the characters of that language or of one of those languages;
2[(b) have its name engraved in legible characters on its seal, if any;]
(c) get its name, address of its registered office and the Corporate Identity Number along with telephone number, fax number, if any, e-mail and website addresses, if any, printed in all its business letters, billheads, letter papers and in all its notices and other official publications; and
(d) have its name printed on hundies, promissory notes, bills of exchange and such other documents as may be prescribed:
Provided that where a company has changed its name or names during the last two years, it shall paint or affix or print, as the case may be, along with its name, the former name or names so changed during the last two years as required under clauses (a) and (c):
Provided further that the words One Person Company shall be mentioned in brackets below the name of such company, wherever its name is printed, affixed or engraved.
(4) Notice of every change of the situation of the registered office, verified in the manner prescribed, after the date of incorporation of the company, shall be given to the Registrar 3[within thirty days] of the change, who shall record the same.
(5) Except on the authority of a special resolution passed by a company, the registered office of the company shall not be changed,--
(a) in the case of an existing company, outside the local limits of any city, town or village where such office is situated at the commencement of this Act or where it may be situated later by virtue of a special resolution passed by the company; and
(b) in the case of any other company, outside the local limits of any city, town or village where such office is first situated or where it may be situated later by virtue of a special resolution passed by the company:
Provided that no company shall change the place of its registered office from the jurisdiction of one Registrar to the jurisdiction of another Registrar within the same State unless such change is confirmed by the Regional Director on an application made in this behalf by the company in the prescribed manner.
(6) The confirmation referred to in sub-section (5) shall be communicated within a period of thirty days from the date of receipt of application by the Regional Director to the company and the company shall file the confirmation with the Registrar within a period of sixty days of the date of confirmation who shall register the same and certify the registration within a period of thirty days from the date of filing of such confirmation.
(7) The certificate referred to in sub-section (6) shall be conclusive evidence that all the requirements of this Act with respect to change of registered office in pursuance of sub-section (5) have been complied with and the change shall take effect from the date of the certificate.
(8) If any default is made in complying with the requirements of this section, the company and every officer who is in default shall be liable to a penalty of one thousand rupees for every day during which the default continues but not exceeding one lakh rupees.
4[(9) If the Registrar has reasonable cause to believe that the company is not carrying on any business or operations, he may cause a physical verification of the registered office of the company in such manner as may be prescribed and if any default is found to be made in complying with the requirements of sub-section (1), he may without prejudice to the provisions of sub-section (8), initiate action for the removal of the name of the company from the register of companies under Chapter XVIII.]
"""

    sections = extract_sections(input_text)
    markdown_output = format_markdown(sections)
    print(markdown_output)