티스토리 뷰
□ Literal characters
Regex: /car/
String: "car"
Regex: /car/
String: "carnival"
Case-sensitivity matters
Regex: /car/
String: "Carnival"
Regex: /car/i
String: "Carnival"
Regex: /Car/i
String: "carnival"
Whitespace matters
Regex: /car/
String: "c a r"
Global modifier
Regex: /zz/
String: "pizzazz"
- 맨 왼쪽, 맨 처음만 선택됨이 디폴트.
Regex: /zz/g
String: "pizzazz"
- g모드에서 전체 매칭.
Regex: /cat/
String: "The cow, camel, and cat communicated."
Regex: /cat/g
String: "The cow, camel, and cat communicated."
□ Metacharacters
종류 : \ . * + - {} [] ^ $ | ? ( ) : ! =
- 맥락에 따라 의미가 달라질 수 있다.
Regex: . * + [abc] ^ $ | ? (abc) \d{2,3}
□ The wildcard metacharacter
Regex: /h.t/ : h(글자하나)h
String: "hat hot hit heat hzt h t h#t h:t"
Regex: /.a.a.a/
String: "banana papaya abacab"
Regex: /a.a.a./
String: "banana papaya abacab"
Write a regex that matches all three words:
Regex:
String: "silver sliver slider"
□ Escaping metacharacters
- 역슬래시(\) 사용해서 메타캐릭터를 피함.
Regex: /9\.00/
String: "9.00 9500 9-00"
String: "his_export.txt her_export.txt"
Regex: /h.._export.txt/
Regex: /h.._export\.txt/
String: "resume1.txt resume2.txt resume3_txt.zip"
Regex: /resume.\.txt/
Also may need to escape /
String: "/home/user/document.txt"
Regex: //home/user/document\.txt/
Regex: /\/home\/user\/document\.txt/
□ Other special ch aracters
- space는 글자.
Regex: /c a t/
String: "c a t"
- 탭은 \t
Regex: /a\tb/
String: "a b"
- 엔터는 \n
Regex: /c\nd/
String: "abc
def"
0xA9 = \xA9
'dev' 카테고리의 다른 글
| 리소스 (1) | 2015.04.21 |
|---|---|
| 파이썬 관련 강좌 올리는 님. django 등 (0) | 2015.02.14 |
| 이클립스 moonrise 테마 (0) | 2015.02.14 |
| 정규식 - Repetition Expressions (0) | 2015.02.02 |
| 정규식 - Character Sets (0) | 2015.01.30 |
