시나리오 :자바 패턴 사용
Pattern whitespace = Pattern.compile("^\\s");
matcher = whitespace.matcher(" WhiteSpace");
Pattern whitespace2 = Pattern.compile("^\\s\\s");
matcher2 = whitespace2.matcher(" WhiteSpace");
나는 줄의 시작 부분에 공백을 얻기 위해 노력하고 있어요. 정확한 공백 문자 수를 얻고 싶습니다. 내 문자열은 " WhiteSpace"
입니다.
matcher
및 matcher2
이이 문자열에서 작동하지 않습니다.
단 1 공백을 얻을 패턴하지만,이 패턴은 2 공백 문자열을 작동하지해야
내가 원하는 건입니다. 아래 시나리오에서 matcher.find()
및 matcher2.find()
이 모두 해당됩니다. 그러나 matcher.find()
은 거짓이어야하며 matcher2.find()
이 true이어야합니다. " WhiteSpace"
:
내가 matcher2가 진실 할
" WhiteSpace"
(두 자리)에 대한
" WhiteSpace"
에 대한 허위 사실로합니다.
내가하고 싶은 일은;
문자열이 " two whitespaces"
입니다.
if 문 양쪽 모두 아래에 있습니다. matcher
은 false 여야합니다. matcher2
이 true이어야합니다.
Pattern whitespace = Pattern.compile("^\\s");
matcher = whitespace.matcher(" two whitespaces");
Pattern whitespace2 = Pattern.compile("^\\s\\s");
matcher2 = whitespace2.matcher(" two whitespaces");
if(matcher.find()==true){
//XXXXXXXXXXX
} else if(matcher2.find()==true){
//YYYYYYYYYYY
}
감사합니다 Pshemo. – ivbtar