텍스트 앞 뒤의 특수문자를 얻는 메서드

 /**
  * 한글/영어/숫자를 둘러싼 특수문자를 얻어내기 위한 함수.
  * 한글 앞, 뒤의 특수문자를 각각 저장해서 스트링 배열 result [0], [1]로 리턴한다.
  * 예를 들어 기존 스트링이 !@#$한글%^&* 이라면
  * result[0] = “!@#$
  * result[1] = “%^&*”을 돌려 받는다.
  * 기존 스트링이 !@#$한글영어한글!@#$%^&*숫자한글영어한글%^&* 이어도 동일한 결과를 리턴받는다.
  * (한글/영어/숫자 사이의 특수문자는 무시)
  *
  * @param origin
  * @return
  */
 public static String[] getOnlySpecialMark_surrounded(String origin){
  String[] result = { “”, “” };
  
  StringBuffer frontBuffer = new StringBuffer();
  StringBuffer backBuffer = new StringBuffer();
  
  boolean discoverd_korean = false;
  
  try{
   int len = origin.length();
   for(int col = 0; col < len; col ++){
    String oneChar = origin.substring( col, col+1 );
       
    boolean thisChar_is_specialMark = !oneChar.matches( “[가-힣0-9a-zA-Z]” );
    
    if( thisChar_is_specialMark ){
     
     //특정 특수문자를 발견하면 추가하고 넘어간다.
     if( hasMark(origin, col, “\\n“) ||
      hasMark(origin, col, “\\r“) ||
      hasMark(origin, col, “\\t“) ){
      oneChar = origin.substring( col , col+2 );
      frontBuffer.append(oneChar);
      continue;
     }
     
     if( !discoverd_korean ){
      frontBuffer.append(oneChar);   
     }
     else{
      backBuffer.append(oneChar);
     }
    }
    else{
     discoverd_korean = true;
     backBuffer.delete( 0, backBuffer.length() );
    }
   }
   
  }catch(Exception ex){
   Err.print(ex);
   return result;
  }
  
  
  //저장
  result[0] = frontBuffer.toString();
  result[1] = backBuffer.toString();
  
  //공백이나 탭만 있을 경우 무의미하므로 지운다
  if( result[0].matches(“\\s*\\t*”) ){
   result[0] = “”;
  }
  
  if( result[1].matches(“\\s*\\t*”) ){
   result[1] = “”;
  }
  
  return result;
 }