2015.12.30 에, 이글루스에 이에 관련한 내용을 썼다.
다음은 원문이다.
Regex 에서 종종 나오는 표현이 ‘Assert’ 다.
이걸 찾아봐도 확실하게 ‘뭐다’라고 나온 것은 볼 수 없었다.
그런데..
Regular Expression Cookbook 을 보다보니, 대충 짐작은 가는 것 같다.
실마리가 된 것은 Zero Width Assertion 이라는 표현이다. 먼저, Assert 가 갖는 기본적인 의미는 ‘(강력히) 주장하다’이다. Regex 에선 이런 의미를 부여해봤자 잘 들어맞질 않는다. 뭘 주장해??
다시 한번 ‘그런데’.
Zero Width Assertion 은 \b 등을 일컫는데, 이것은 ‘찾되(Match) 표시하지 않음’을 뜻한다.
이것으로 미루어 짐작해보면, Assert 는 그냥 Zero Width Assert 와 같다고 봐도 큰 무리가 없을 것 같다.
즉, 찾기는 하되 그것을 결과로 나타내지는 않음. 어찌보면 ‘(찾는 것이) 있음을 (강력히) 주장함.’ 정도로 이해하면 될 것 같다.
그리고, 오늘(19.09.10), 한가지를 추가한다.
위에서 내가 짐작한 내용은 맞는 듯 하다.
Regex Info 의 Lookaround 에 관련된 글에 이런 내용이 있다.
Lookahead and lookbehind, collectively called “lookaround”, are zero-length assertions just like the start and end of line, and start and end of word anchors explained earlier in this tutorial. The difference is that lookaround actually matches characters, but then gives up the match, returning only the result: match or no match. That is why they are called “assertions”. They do not consume characters in the string, but only assert whether a match is possible or not. Lookaround allows you to create regular expressions that are impossible to create without them, or that would get very longwinded without them.
Assert 는 ‘주장’을 뜻하는데, 그 주장도 ‘단호함, 확고함’을 포함하고 있다. 따라서, 위에 내가 쓴 표현이 맞다고 볼 수 있다.
또는, ‘일치’가 됐음을 주장만 하고, 행동에는 옮기지 않음을 표현하기위해, Assert 라는 용어에 초점을 맞췄는지도 모르겠다.