1. regex 중 matching pattern reuse
1) %s/abcd\(.*\)z/aaaa\1a/g
--> "abcd"로 시작해서 "z"로 끝나는 문자열을 "aaaa"로 시작해서 "a"로 끝나는 문자열로 바꾼다.
--> 예) abcd1234z --> aaaa1234a, abcdefghi..z --> aaaaefghi..a
2) %s/abcd\(.*{1,10}\)123\(.*\)0/1234\1abc\2z/g
--> "abcd*123*0" 형태의 문자열을 "1234*abc*z"형태로 바꾼다.
--> 예) abcdefg1234560 --> 1234efgabc456z
2011년 7월 28일 목요일
2011년 3월 28일 월요일
Regular expression for survival
0. A truth for the regular expression
Regular expression is used to matching pattern in a line. (Not laid on multiple lines.)
1. The Structure of a regular expression
1) Anchors
(1) ^ : begin of a line
(2) $ : end of a line
(3) \< ... \> : word level matching.
2) Character sets
(1) . : any char except the EOL char.
(2) [...] : any char in brackets.
a. range : [a-z], [0-9], [A-Za-z0-9_]
b. order : "^T[a-z][aeiou] " : Tha, The, Thi, ...
(3) [^...] : negate pattern. except chars in brackets.
(4) \( ... \) : remembered pattern. use it with "\1 ~ \9"
3) Modifiers : follows a character set. if not, not a modifier.
(1) * : 0 or more copies
(2) {a,b} : # of copies between a and b.
Regular expression is used to matching pattern in a line. (Not laid on multiple lines.)
1. The Structure of a regular expression
1) Anchors
(1) ^ : begin of a line
(2) $ : end of a line
(3) \< ... \> : word level matching.
2) Character sets
(1) . : any char except the EOL char.
(2) [...] : any char in brackets.
a. range : [a-z], [0-9], [A-Za-z0-9_]
b. order : "^T[a-z][aeiou] " : Tha, The, Thi, ...
(3) [^...] : negate pattern. except chars in brackets.
(4) \( ... \) : remembered pattern. use it with "\1 ~ \9"
3) Modifiers : follows a character set. if not, not a modifier.
(1) * : 0 or more copies
(2) {a,b} : # of copies between a and b.
라벨:
dev tip,
regex,
regular expression
피드 구독하기:
글 (Atom)