Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
regular_expression [2022/10/16 14:11] – 기본 개념 전체 정리 ledyxregular_expression [2022/10/16 16:21] (current) – 문단 수정 ledyx
Line 7: Line 7:
 = 기본 개념 = = 기본 개념 =
  
-== Metacharacters ==+== Basic Metacharacters ==
  
 |<100%>| |<100%>|
Line 21: Line 21:
 |   <nowiki>\</nowiki>    |   Metacharacter를 일반 문자로 인식  | |   <nowiki>\</nowiki>    |   Metacharacter를 일반 문자로 인식  |
  
-=== 범위 ===+== 범위 ==
  
 |<100%>| |<100%>|
Line 38: Line 38:
 |   <nowiki>\W</nowiki>    \w와 반대로 일치  |  <nowiki>[^a-zA-Z0-9_]</nowiki> 와 같음  | |   <nowiki>\W</nowiki>    \w와 반대로 일치  |  <nowiki>[^a-zA-Z0-9_]</nowiki> 와 같음  |
  
-=== 공백 문자 ===+== 공백 문자 ==
  
 |<100%>| |<100%>|
Line 102: Line 102:
 == Lookaround == == Lookaround ==
  
-일치하는 영역을 제외하고, 일치하는 영역 기준으로 이전 혹은 이후 값을 반환+일치하는 영역을 제외하고, 일치하는 영역 기준으로 이전 혹은 이후 값을 반환.
  
-=== Lookahead ===+부정형은 "<nowiki>=</nowiki>" 대신 "!"을 대체한다.
  
-전방 탐색+|<100%>
 +^  Metacharacter  ^  설명 
 +|   <nowiki>(?=)</nowiki>  |   긍정형 전방탐색 (Positive Lookahead) 
 +|   <nowiki>(?<=)</nowiki>  |   긍정형 후방탐색 (Positive Lookbehind)  |
  
-  * Positive : <nowiki>?=</nowiki> +^  Metacharacter  ^  설명 
-  Negative <nowiki>?!</nowiki>+  <nowiki>(?!)</nowiki>  |   부정형 전방탐색 (Negative Lookahead) 
 +|   <nowiki>(?<!)</nowiki>    부정형 후방탐색 (Negative Lookbehind) 
 + 
 +=== 예시 ===
  
 +  * 긍정형 전방탐색
  
 <code> <code>
Line 119: Line 126:
 <bg skyblue>https</bg><nowiki>://mail.google.com</nowiki> \\ <bg skyblue>https</bg><nowiki>://mail.google.com</nowiki> \\
 <bg skyblue>ftp</bg><nowiki>://ftp.xxx.xyz</nowiki> \\ <bg skyblue>ftp</bg><nowiki>://ftp.xxx.xyz</nowiki> \\
 +
 +  * 긍정형 후방탐색
 +
 +<code>
 +(?<=\$)[0-9.]+
 +</code>
 +
 +A11 : $<bg skyblue>23.34</bg> \\
 +B22 : $<bg skyblue>5.31</bg> \\
 +Total items found : 2
 +
 +  * 부정형 전후방탐색
 +
 +<code>
 +\b(?<!\$)\d+\b
 +</code>
 +
 +I paid $30 for <bg skyblue>100</bg> apples,
 +<bg skyblue>50</bg> oranges, and <bg skyblue>60</bg> pears.
 +I saved $5 on this order.
  
  
Line 140: Line 167:
  
  
-===  Lookbehind  === 
-후방 탐색.  
  
-  * Positive : <nowiki>?<=</nowiki> +언어별 활용 =
-  * Negative : <nowiki>?<!</nowiki>+
  
-<code> +== Java ==
-(?<=\$)[0-9.]+ +
-</code> +
- +
-A11 : $<bg skyblue>23.34</bg> \\ +
-B22 : $<bg skyblue>5.31</bg> \\ +
-Total items found : 2 +
- +
- +
-= Java =+
  
 https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html
Line 165: Line 180:
 </sxh> </sxh>
  
-== Pattern Constant ==+=== Pattern Constant ===
  
 <sxh> <sxh>
Line 177: Line 192:
 </sxh> </sxh>
  
-== POSIX character classes (US-ASCII only) ==+=== POSIX character classes (US-ASCII only) ===
  
 <sxh> <sxh>
Line 193: Line 208:
 \p{XDigit} A hexadecimal digit: [0-9a-fA-F] \p{XDigit} A hexadecimal digit: [0-9a-fA-F]
 \p{Space} A whitespace character: [ \t\n\x0B\f\r] \p{Space} A whitespace character: [ \t\n\x0B\f\r]
-</sxh> 
-= 활용 = 
- 
-== 전화번호 == 
-<sxh java> 
-^(02|0[3-6]{1}[1-5]{1})-?[0-9]{3,4}-?[0-9]{4}$ //지역번호-xxx(x)-xxxx 
-^(15(44|77|88|99)|1644)-?[0-9]{4}$ //15xx/1644-xxxx 
-</sxh> 
- 
-== 소괄호 안 문자(= Parameter) 추출 == 
-<sxh java> 
-String str = "(int a, int b)"; 
- 
-Pattern p = Pattern.compile("\\((.*?)\\)"); 
-Matcher m = p.matcher(str); 
- 
-while(m.find()) 
- System.out.println(m.group(1)); 
 </sxh> </sxh>
  
regular_expression.1665925895.txt.gz · Last modified: 2022/10/16 14:11 by ledyx