Notice
Recent Posts
Recent Comments
Link
250x250
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Webpack
- expire_logs_days
- REACT
- update
- log_bin
- Express
- REACTJS
- npm
- Spring Batch
- Node
- Regular expression
- mysql 5.5
- upgrade
- regex
- log4j2
- Effective Java 3/e
- Chunk
- java
- current_date
- spring
- migration
- MySQL
- JavaScript
- git
- spring cloud
- nodejs
- eslint
- 퀵소트
- 정규표현식
- Effective Java
Archives
- Today
- Total
내 세상
[Java] 정규 표현식 (Regex) Pattern, Matcher 사용 본문
728x90
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class CodeRunner{
public static void main(String[] args)
{
Pattern p = Pattern.compile("_([0-9]+).txt$", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher("ABC_TEST_BABO_GOSU_COMPUTER_10.txT");
if(m.find()){
System.out.println(m.group(1));
}
}
}
round bucket, 괄호, (
=> 괄호로 묶을 경우, group으로 칭한다.
m.group(1)
=> Matcher에서 첫번째 그룹을 가져온다는 의미.
=> 단, 0을 입력하면 전체를 다 가져옴.
=> 반드시 m.find() 후 사용해야함. 위의 구조 사용 필수.
728x90
'Language > Java' 카테고리의 다른 글
[Java] Java Stream (0) | 2022.04.06 |
---|---|
[Java] 현재 시간을 yyyyMMddHHmmss String으로 추출하는 코드 (0) | 2022.01.04 |
[Java] Log4j 1.x to Log4j 2 Migration - Configuring Log4j 2 (0) | 2021.12.14 |
[Java] Log4j 1.x to Log4j 2 Migration - Converting to the Log4j 2 API (0) | 2021.12.14 |
[Java] Effective Java 3/e - Item 12) toString을 항상 재정의하라 (0) | 2021.12.06 |