Привет, я хочу искать и получить индекс всех специальных Chars в такой сложной строке, как эта < /p>
String textWithSpecialChars = "text here |*more*| text some other |@tags@|...";
< /code>
Я пытаюсь искать все шаблоны, подобные этому | * | _ | = |@< /code> и * | _ | = | @| < /code> я пробую эти шаблоны < /p>
public int getIndexOfPat(String s){
Pattern startPat = Pattern.compile("\\|[\\*_@=]");
Matcher matcher = pattern.matcher(s);
return matcher.find() ? matcher.start() : -1;
}
String textWithSpecialChars = "text here |*more*| text some other |@tags@|...";
int i = getIndexOfPat(textWithSpecialChars);
textWithSpecialChars = textWithSpecialChars.substring(i+2);
//I get error here
i = getIndexOfPat(textWithSpecialChars);
// var i still is the first one value
< /code>
Но это только получает первый, даже если я удаляю ее из исходной строки с < /p>
Подробнее здесь: https://stackoverflow.com/questions/249 ... cial-chars