2013-01-08 10 views
1

오라클 설명서에는 다음과 같은 문구가 있습니다.RegEx에서 메타 문자를 일반 문자로 강제 적용

metachatecters 제가

이해 <([{\^-=$!|]})?*+.>
There are two ways to force a metacharacter to be treated as an ordinary character: 

    * precede the metacharacter with a backslash, or 
    * enclose it within \Q (which starts the quote) and \E (which ends it). 

첫번째 방법.

두 번째 방법에 대해 자세히 설명 할 수 있습니까?

:

감사

답변

3
* enclose it within \Q (which starts the quote) and \E (which ends it). 

\Q\E 사이 $을 둘러싸 아래와 같이해야 $ 메타 문자와 지금 당신이 두번째 방법을 사용하여 일반 문자로 취급하려는 고려
"\\Q$\\E" (eqvivalent to `\\$`) 

그러나 아직까지는를 피해야합니다.및 \E은 유효한 이스케이프 시퀀스가 ​​아니기 때문에 백 슬래시가 추가로 사용됩니다.

0

특수한 Pattern.quote (String) 메서드가 있습니다. 이것은 기본적으로 내부적으로

int slashEIndex = s.indexOf("\\E"); 
    if (slashEIndex == -1) 
     return "\\Q" + s + "\\E"; 

무엇이며 문자열이 "\\E" 시퀀스가 ​​포함 된 경우 그것은 그들에게

을 피할 것
관련 문제