java regular expression(정규표현식)


study
http://zvon.org/comp/r/tut-Regexp.html#Pages~Page_3
http://regexone.com/

----------------------------------------------------------------------
package testjava;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TPattern {
public static void main(String[] args){

String regularExpression = "^who";
String source =  "who is who";
String originalSource = source;

Matcher m = Pattern.compile(regularExpression).matcher(source);
source = source.replaceAll(regularExpression, "####");

System.out.println("regx\t\t:"+regularExpression);
System.out.println("original\t:"+originalSource);
System.out.println("source\t\t:"+source);
System.out.println("find\t\t:"+m.find());
System.out.println("matches\t\t:"+m.matches());

}

}
--------------------------------------------------------------------------------------------------
result :
regx :^who
original :who is who
source :#### is who
find :true
matches :false


--------------------------------------------------------------------------------------------------
패턴  뜻  패턴(예)  문자열  결과 
.  임의의 한 문자 (문자의 종류 가리지 않음), 단, \ 는 넣을 수 없음 a.c  abcde  abc 
[]  문자의 집합이나 범위를 나타내며 두 문자 사이는 - 기호로 범위를      나타낸다. []내에서 ^가 선행하여 존재하면 not 을 나타낸다. [ab]c ac bc dc ac, bc
[^] 집합 제외 [^a]d   ad bd cd bd, cd 
^  문자열의 시작 ^12  12 312 12 
 *  앞 문자가 없을 수도 무한정 많을 수도 있음      
$  문자열의 종료 cat$  bcat cat cat(뒤 cat)
\ 특수문자 앞 c\[b\] abc[b] c[b]
\d  숫자 [0-9]와 동일 \d  123abc  1, 2, 3
\D   숫자를 제외한 모든 문자 \D 123abc  a, b, c
\w  알파벳이나 숫자 \w 123abc!@#  1, 2, 3, a, b, c
\W   알파벳이나 숫자를 제외한 문자 \W  123abc!@#  !, @, #
\s 모든 공백 \s ab cd  ab cd (주황색 위치)
\S  공백 문자가 아닌 나머지 문자 \S  ab cd 
+  앞 문자가 하나 이상 \d+ 123abc456 123, 456
?  앞 문자가 없거나 하나있음 a?d  ad bd cd ad, d, d 
{}  횟수 또는 범위를 나타낸다. \d{3} 123 456789  123, 456, 789
  2~3개 \d{2,3}  1 12 123  12, 123 
  최소 3개  \d{3,}  1 12 123  123 
\b 단어 경계 \b11   11 211  11 
    11\b   11 211  11, 11 
 |  패턴 안에서 or 연산을 수행할 때 사용      
 ()  소괄호 안의 문자를 하나의 문자로 인식       
(?=)  전방탐색 a(?=b) ab a
(?<=) 후방탐색  (?<=a)b ab b
(?!) 부정 전방탐색  a(?!c) ab ac  a (앞 a) 
(?<!) 부정 후방탐색  (?<!b)a ca ba  a (앞 a) 
(?(조건)true) 역참조  a(?(?=-)-b) a a- a-b a, a-b
(조건)? (?(1)true) 역참조 (a)?b(?(1)c) abc b abc, b


Popular posts from this blog

com.gpki.secureweb.GPKISecureWEBException: ErrCode=1507,ErrMsg=[GPKI_CMS_ProcessEnvelopedData] 해당 인증서로는 데이터를 풀 수 없습니다.

PL/SQL Developer Tip 선택한 것만 실행