문자열을 나누는 split 함수에서 구분자로 + 를 사용하면
(+ 뿐만 아니라, *, ^ 도 마찬가지)
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0
라는 예외가 발생한다.
이유는 정규표현식에서 사용되는 문자이기 때문인데 단순문자인 구분자로 사용하고 싶으면 escape 시켜야 한다.
` ` `
They are called quantifiers.
* 0 or more of the preceding expression
+ 1 or more of the preceding expression
from: https://stackoverflow.com/questions/8575281/regex-plus-vs-star-difference
Regex plus vs star difference?
What is the difference between: (.+?) and (.*?) when I use it in my php preg_match regex?
stackoverflow.com
` ` `
"[+] " , "\\+"
<escape 전>
<escape 후>
'공부내용 정리 > 자바' 카테고리의 다른 글
[JAVA] 람다(lambda) 표현식 (3) | 2024.12.20 |
---|---|
[JAVA] 1byte (1) | 2024.12.20 |
Substring 문자열 자르기 (2) | 2023.10.24 |
의존성 주입 (Dependency Injection, DI) (1) | 2023.10.17 |
JDBC 프로그래밍 (0) | 2023.10.11 |