from typing import Match


def gen_ruby_bbcode(match: Match) -> str:
    """Convert matched ruby tex code into bbcode for bbs usage
    \ruby{A}{B} -> [ruby=B]A[/ruby]

    Also support | split ruby
    \ruby{椎名|真昼}{しいな|まひる} -> [ruby=しいな]椎名[/ruby][ruby=まひる]真昼[/ruby]
    """
    return ''.join('[ruby={}]{}[/ruby]'.format(*pair) for pair in
                   zip(match.group('ruby').split('|'), match.group('word').split('|')))