[완료] 한글 grep

babbab의 이미지

몇칠 전에 google에서 wchar_t로 쓸수 있는 tre라는 정규식 라이브러리를 발견했습니다.
wchar_t가 되면 정규식에서 [가나다] 뿐만 아니라 .도 한글 한문자로 인식, 한글이 정규식에서 된다는 말입니다.
그 tre로 한글 grep을 허접하게 만들어 봤는데 실행되긴 돼더라고요. 윈도우 7은 유니코드를
쓰다고 알고 있습니다.

윈도우 7에서 visual c++ express 2008으로 (무료 ㅋㅋㅋ) 컴파일 했습니다.
tre.dll배포하는 라이센스는 불법인지 합법인지 모르겠지만 어쨌건 첨부해습니다(없으면
프로그램이 않돌아 가니까) visual c++ redistable도 첨부했습니다. win xp에서 없으면 않돌아가더라고요.

이제 한글sed, 한글ed, 한글awk, 한글... 이 더욱 가까워진 느낌입니다.
첨 만든거라 버그가 있을겁니다. -_-a;;

한번 써보시고 조언이나 찾은 버그등을 댓글로 남기면 고맙겠습니다.

File attachments: 
첨부파일 크기
Package icon hgrep.zip4.34 MB
익명 사용자의 이미지

http://laurikari.net/tre/download/

TRE는 BSD라이선스네요. 아무런 문제 없겠습니다. 수고하셨습니다 ^^

익명 사용자의 이미지

제가 처음 tre를 컴파일할때 애먹었는데 이런 글귀를 그사이트에서 발견했습니다.

Hi Ville,
I tried to run the retest application in MS Visual Studio in debug mode … but it would not run because there was an error in the tre.vsproj configuration file that I loaded from darcs:
The additional link library (for project “tre”: properties/configuration properties/Linker/Input/Additional Dependencies) for debug configuration should be “mscvprtd.lib”.
After I added the “d” character to to library everything was ok!
Regrads, Enno.

msvcprtd.lib여야 하는데 msvcprt.lib라고 문자가 잘못찍혀 있다고요.( 그 글귀도 msvcprtd.lib를 mscvprtd.lib로 잘못찍은것입니다 )
후에 윈도우 7에선 잘되고요.

리눅스는 제가 리눅스를 더이상 쓰지않아서 tre가 아무문제나 편집없이 컴파일 되는줄 모르겠습니다.
리눅스에서도 컴파일 되면 댓글올려주세요. ;)

익명 사용자의 이미지

tre가 꽤 괜찮은가보네요. netbsd의 기본 regex 라이브러리로 들어가있나봅니다. 덕분에 라이선스도 제한없는 BSD라이선스로 바뀌어버렸다고 홈페이지에 나와있네요.

bootmeta의 이미지

tre 관련해서 몇가지 찾아보니 google에서 open source로 공개한 RE2 라이브러리가 꽤 괜찮아 보입니다.

http://code.google.com/p/re2/

나름 장단점이 있겠습니다만, RE2가 퍼포먼스 측면에서 다른 라이브러리들을 압도하는군요.
http://sljit.sourceforge.net/regex_perf.html 퍼포먼스 비교

RE2 개발자 왈
"어찌된게 요즘 perl, java, python, ruby, php에서 사용하는 녀석이 Thompson이 awk, grep에서 사용한 수십년 전 것(C언어 창시자 thomson 방식)보다 덜떨어졌다니 하늘이 통탄할 일이로다"
(물론 과장된 표현이고 perl등에서 왜 다른 방식을 사용하는지도 해당 문서에서 설명합니다.)

http://swtch.com/~rsc/regexp/regexp1.html

익명 사용자의 이미지

re2의 첨 웹페이지를 읽어보니 submatch는 되나 backreferencing이 않된다고 되있더라고요.
syntax페이지 Unicode character class names--scripts:밑에 한글도 있고.
wchar_t가 된단 얘긴가요?
그리고 밑에 백레퍼랜싱이나 요게 generalized assertions 필요하면 irregexp, Google Chrome's regular expression engine에 관심이 있을 것다라고 있네요.

제가 알기론 Henry Spencer regex lib도 존재하는걸로 알고 있습니다. (한글은 않되지만)

bootmeta의 이미지

저도 자세히 살펴보지 않아 wchar_t 지원여부는 모릅니다. --;
java, perl등에서 thomson 방식을 사용하지 않는 결정적 이유가 back reference 지원 때문이겠죠.
(단점보다 범용성이 더 중요하다고 봤겠죠.)

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.