Извлечение шаблона из строки с неизвестной длинойJAVA

Программисты JAVA общаются здесь
Anonymous
Извлечение шаблона из строки с неизвестной длиной

Сообщение Anonymous »

Я все еще в очень эмбриональной стадии в Java, и я пытаюсь выяснить, как извлечь все конкретные значения. < /p>

, которые в этой форме (шаблон) [a-h] [1-8] < /code> из строки, какая длина неизвестна.

, например, если моя строка-«f5 f4 e3» < /code a wit a a with fo nate> i hate a a wit a a wit to fn> code> i hate a a wit to a disege> i hate a wit a distaint a a a wit vis> vis> vis> a wit a a wit to fo e3 e3 ». Переменная, f4 < /code> к переменной, E3 < /code> к другой переменной. < /p>

или, если моя строка будет «a2» < /code> Я хотел бы назначить a2 < /code> переменную. Пространства "blanke2blank" < /code>. < /p>

Это мой код до сих пор: < /p>

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Arrays;

public class List {
public static void main(String[] args) {

int i = 0;
char[] Wanted = new char[]{?}; // What should I use here?
Pattern pat = Pattern.compile("\\s*d+\\s*D+\\s*d+");
String Motherstring = " F5 F4 E3 "; // this is just an example but the extraction should work for every string
Matcher m = pat.matcher(Motherstring);
while (pat.find()) {
Wanted = pat; // ?
i++;
}
}
}


Подробнее здесь: https://stackoverflow.com/questions/268 ... own-length

Вернуться в «JAVA»