당신은 \z
와 문자열의 끝을 정의 할 수 있습니다 다음은 텍스트입니다.
"\\*{5,}\\z"
건배 :
그래서 루비 형식으로,이 트릭을 할 것입니다!
나를 위해 작동
, 나는 여기에서 그것을 테스트했습니다
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class Untitled {
public static void main(String[] args) {
String test = " ************************************\n" +
"* *\n" +
"* *\n" +
"* Source: Test *\n" +
"* *\n" +
"* Amount: $6.50 *\n" +
"* *\n" +
"************************************";
Pattern pattern = Pattern.compile("\\*{5,}\\z");
// In case you would like to ignore case sensitivity you could use this
// statement
// Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(test);
// Check all occurance
while (matcher.find()) {
System.out.print("Start index: " + matcher.start());
System.out.print(" End index: " + matcher.end() + " ");
System.out.println(matcher.group());
}
}
}
출력 : 260 최종 인덱스 : 인덱스 시작 296 * * http://www.regexplanet.com/simple/index.html
OK, 정말 작동합니까 * * ** * ** * ** * ** * ****
이 모든 것이 단일 문자열입니까? –
예, 모두 한 텍스트에 있습니다. 별의 첫 번째 줄 앞에 텍스트가 있지만 별의 마지막 줄 뒤에 아무 것도 없습니다. – Leger