Группа регулярных выражений Java останавливается при первом результате ⇐ JAVA
Группа регулярных выражений Java останавливается при первом результате
My regex is (without java escapes) //(?:\[?([^\]\[]+)\]?)+\n , which should capture lines starting with // and following an optional [ some not bracket characters than a ] , and this could be multiple times before the line ending.
For example //[a]\n should result in group a, but I would assume //[c]\n should result group b and c. But The result is the following instead:
Full match: //[c] //[a] Group 1: a What do I miss? Why Having full match for [c] doesn't result a group b and c ?
This is my test code:
public static void main(String[] args) { final String regex = "//(?:\\[?([^]\\[]+)\\]?)+\\n"; final String string = "//[c]\n" + "//[a]\n" + "dfdsfg"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i
Источник: https://stackoverflow.com/questions/781 ... rst-result
My regex is (without java escapes) //(?:\[?([^\]\[]+)\]?)+\n , which should capture lines starting with // and following an optional [ some not bracket characters than a ] , and this could be multiple times before the line ending.
For example //[a]\n should result in group a, but I would assume //[c]\n should result group b and c. But The result is the following instead:
Full match: //[c] //[a] Group 1: a What do I miss? Why Having full match for [c] doesn't result a group b and c ?
This is my test code:
public static void main(String[] args) { final String regex = "//(?:\\[?([^]\\[]+)\\]?)+\\n"; final String string = "//[c]\n" + "//[a]\n" + "dfdsfg"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i
Источник: https://stackoverflow.com/questions/781 ... rst-result
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Что такое вариант в мире регулярных выражений и какой вариант использует Java?
Anonymous » » в форуме JAVA - 0 Ответы
- 26 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Проблема с шаблоном регулярных выражений (разбиение строки на символы и цифры) в Java
Anonymous » » в форуме JAVA - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-