그동안 네이버 지식인 답변달면서 시간에 쫓겨 질낮은 답만 양산했는데..

지식인 관두고나니 공부할 시간이 조금 늘었다.

도움도 안되는(간혹.. 아주 가끔 도움이 되는 질문도 있었지만..) 지식인 관두고, 그냥 하고 싶은거 조금씩 정리해 둬야겠다.

 

 

0 .TXT - regex_test_03.txt

 

From Wikipedia, the free encyclopedia
This article is about the comic book company using this name beginning in 1961.
For the earlier comic book 12.3 series, see Marvel Mystery // Comics.
Marvel Comics //
//MarvelLogo.svg //+ -
/Parent company Marvel /Entertainment, // LLC
(The Walt /*Disney Company */)
///Status Active
// 가나다라
마바사

 

 

1. CLASS

 

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

 

public class t0418_PatternSep_1131 {
  public static void main(String arg[]){
    Scanner sc;
    Scanner scIn;
    StringBuffer repStr = new StringBuffer();
  
    String txtMun = "";
  
    File tempDir = new File("D:\\WORK\\txt\\");
    File[] TempFiles = tempDir.listFiles();

 

    for(File tf : TempFiles){
      if(tf.isFile() && tf.getName().matches("regex_test_03.txt")){
        System.out.println(tf.getName());
    
        try {
          sc = new Scanner(new File(tf.toString()));
          while(sc.hasNextLine()){
            txtMun += sc.nextLine() + "\n";
          }
        } catch (FileNotFoundException e) {
          e.printStackTrace();
        }
      }
    }
    System.out.println(txtMun);
    System.out.println("\n---------------------------------------------------------------\n");
  
    scIn = new Scanner(System.in);
    System.out.println("검색할 문자 입력! ");
    String input = scIn.nextLine();

    // Pattern p = Pattern.compile(".(?i)" + input + ".(\\S)+"); // 칸 뛰움 전까지 검색
    Pattern p = Pattern.compile(".(?i)" + input + ".+[^\r\n|\n|\r]"); // 개행 전까지 검색, 빈 개행열 제거
    Matcher m = p.matcher(txtMun);
     
    while(m.find()){
      System.out.println(m.group());
    }
  }
}

 

 

2. RUN

 

regex_test_03.txt
From Wikipedia, the free encyclopedia
This article is about the comic book company using this name beginning in 1961.
For the earlier comic book 12.3 series, see Marvel Mystery // Comics.
Marvel Comics //
//MarvelLogo.svg //+ -
/Parent company Marvel /Entertainment, // LLC
(The Walt /*Disney Company */)
///Status Active
// 가나다라
마바사

 


---------------------------------------------------------------

 

검색할 문자 입력!
ma
 Marvel Mystery // Comics.
/MarvelLogo.svg //+ -
           Marvel /Entertainment, // LLC