| 4 번 글: [GNU sed] 메타 문자와 그룹화 |
| 글쓴이: 산이
[홈페이지]
|
글쓴날: 2003년 01월 09일 00:13:01 목(새벽) |
조회: 4503 |
다른 정규표현식과 상당히 헷갈리는 sed
(자주 잊어먹음)
예)
$ echo 'abc(def)g' | sed 's/^\([^(]\+\)(\([^)]\+\))/\1_\2_/g'
abc_def_g
's/^\([^(]\+\)(\([^)]\+\))/\1_\2_/g'
^^^^^^^^^^ ^^^^^^^^^^
abc ( def )
\1 \2
메타문자를 구룹화할 경우 탈출(\) 문자추가
(다른 정규표현식과 다른점)
+ -> \+ -> 문자 집합([class])에 대한 하나 이상
() -> \(\) -> 그룹화에 사용 -> \1, \2, \3, ... \9
{} -> \{\} -> 반복범위 지정
| -> \| -> or 연산
-----------------------
^ -> 메타문자, 라인의 시작
$ -> 메타문자, 라인의 끝
[] -> 메타문자, 어떤 문자들의 집합, 메타문자로 인식
\ -> 메타문자, 메타문자를 탈출
* -> 메타문자, 문자 집합에 대한 0 이상 /*** 주의 ***/
. -> 메타문자, 어떤 문자든지 매칭
() -> '('와 ')' 문자, 메타문자로 인식하지 않음
? -> '?' 문자, 메타문자로 인식하지 않음
\` - matches the beginning of the pattern space (same as "^")
\' - matches the end of the pattern space (same as "$")
\? - 0 or 1 occurrences of previous character: same as \{0,1\}
\+ - 1 or more occurrences of previous character: same as \{1,\}
\| - matches the string on either side, e.g., foo\|bar
\b - boundary between word and nonword chars (reversible)
\B - boundary between 2 word or between 2 nonword chars
\n - embedded newline (usable after N, G, or similar commands)
\w - any word character: [A-Za-z0-9_]
\W - any nonword char: [^A-Za-z0-9_]
\< - boundary between nonword and word character
\> - boundary between word and nonword character
[[:alnum:]] -> [A-Za-z0-9] Alphanumeric characters
[[:alpha:]] -> [A-Za-z] Alphabetic characters
[[:blank:]] -> [ \x09] Space or tab characters only
[[:cntrl:]] -> [\x00-\x19\x7F] Control characters
[[:digit:]] -> [0-9] Numeric characters
[[:graph:]] -> [!-~] Printable and visible characters
[[:lower:]] -> [a-z] Lower-case alphabetic characters
[[:print:]] -> [ -~] Printable (non-Control) characters
[[:punct:]] -> [!-/:-@[-`{-~] Punctuation characters
[[:space:]] -> [ \t\v\f] All whitespace chars
[[:upper:]] -> [A-Z] Upper-case alphabetic characters
[[:xdigit:]] -> [0-9a-fA-F] Hexadecimal digit characters
URL
http://www.ptug.org/sed/sedfaq.htm
EOF
|
이전글 : [PHP] strtr, preg_replace, str_replace
다음글 : [grep /egrep]
|
from 61.254.75.40
JS(Redhands)Board 0.4 +@
|
|