2011-10-11 3 views
0

자바 정규식을 사용하고 있습니다.역 정규 표현식을 부정하는 방법

{emp.address.street}{emp.name}{emp.surname}

:

the location is at with the name ,

지금 내가 결과를 다음 얻기 위해이 역 할 : 위의 문자열을

String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}"; 

을 따를 내가 문자열을 가지고, s.replaceAll("\\{(.*?)\\}", "") 다음과 같은 문자열을 반환

답변

1

이 테스트 스크립트는 나를 위해 작동 : 위대한

public class TEST 
{ 
    public static void main(String[] args) 
    { 
     String s = "the location is at {emp.address.street} with the name {emp.name},{emp.surname}"; 
     String result = s.replaceAll("[^{}]+|(\\{(.*?)\\})", "$1"); 
     System.out.println(result); 
    } 
} 
+0

... 당신이 어떻게 작동하는지 설명해 주시겠습니까? $ 1의 역할은 무엇입니까? – xbmono

0

Pattern을 만들고 01을 사용할 수 있습니다및 Matcher.group()을 사용하여 패턴의 일부를 가져옵니다. 다음 수업에 대한 Javadoc과을의 : Matcher javadocPattern javadoc

관련 문제