Skip to content

regex의 필요성 검증 #2

Description

@fetiu

regex가 필요하다면, 구체적으로 어떤 상황인지 파악해보자.

예를들어, 다음의 정규식은 분리된 자모음의 패턴을 초성, 중성, 종성 단위로 찾아오는 것이다.
KOR_REGEX = re.compile("([ㄱㄲㄴㄷ-ㄹㅁ-ㅃㅅ-ㅎ])([ㅏ-ㅖㅛㅠㅣ]|ㅗ[ㅏㅐㅣ]?|ㅜ[ㅓㅔㅣ]?|ㅡㅣ?)(?:([ㄲㄷㅁㅅ-ㅈㅊ-ㅎ]|ㄱㅅ?|ㄴ[ㅈㅎ]?|ㄹ[ㄱㅁㅂㅅㅌ-ㅎ]?|ㅂㅅ?)(?![ㅏ-ㅣ]))?")

하지만, 이 이전에, 한글문자를 string에서 찾아낸 뒤에 그 문자만 분리를 시킨다면 패턴 매칭없이 그저 진행 할 수 있지 않을까?

  • multi byte string에서 wide char 스트링 타입으로의 변환이 필요할 수 있다
  • keymap의 API를 사용하게되면, 변환 될 수 없는 문자들은 'NULL'로 반환된다. 이를 활용하면, 별다른 패턴 매칭 없이도 시간복잡도 면에서 효율적이게 만들 수 있을 듯 하다.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions