패턴 22 - \b : 워드(단어)의 경계선
워드 (단어) 경계는 한쪽은 \w이면서 다른 한쪽은 \W인 두 문자 사이의 틈 의미.
어느 쪽으로든 마찬가지. (예) |Homzzang|.|com| |is| |good|. 에서 | 가 경계임.
\w : 알파벳, 숫자, _ (언더바)에 해당하는 문자 (= 단어에 해당하는 것)
\W : 알파벳, 숫자, _ (언더바)가 아닌 모든 문자 (= 단어에 해당하지 않는 것)
Source | (단어의 경계선 의미)
|Ere| |iron| |was| |found| |or| |tree| |was| |hewn|,
|
Case 1 - 단어의 경계선 뒤의 어느 한 문자
Regular Expression: |
\b. |
---|
First match: |
Ere iron was found or tree was hewn, |
---|
All matches: |
Ere iron was found or tree was hewn, |
---|
Case 2 - 단어의 경계선 앞의 어느 한 문자
Regular Expression: |
.\b |
---|
First match: |
Ere iron was found or tree was hewn, |
---|
All matches: |
Ere iron was found or tree was hewn,
|
---|
주의 : 정규식의 단어는 1byte 문자만을 포함해서, 2byte인 한글의 경계는 /b 이용해 표현할 수 없음.
http://ohgyun.com/392 참고할 것.
참고1
\b\w : 앞에 단어 경계선이 위치하는 단어
처음 매치 Ere iron was found or a tree was hewn,
모두 매치 Ere iron was found or a tree was hewn,
\w\b : 뒤에 단어 경계선이 위치하는 단어
처음 매치 Ere iron was found or a tree was hewn,
모두 매치 Ere iron was found or a tree was hewn,
\b\w\b : 단어 경계선이 앞뒤로 위치하는 단어 1글자
처음 매치 Ere iron was found or a tree was hewn,
모두 매치 Ere iron was found or a tree was hewn,
\b\w+\b : 단어 경계선이 앞뒤로 위치하는 단어 1글자 이상 (단어 식별)
처음 매치 Ere iron was found or a tree was hewn,
모두 매치 Ere iron was found or a tree was hewn,
참고2
\bcat : 앞에 단어 경계선이 위치하는 cat 문자
처음 매치 cat concat
모두 매치 cat concat
cat\b : 뒤에 단어 경계선이 위치하는 cat 문자
처음 매치 cat concat
모두 매치 cat concat
최신댓글