Объясните что за фигня. Вот класс.
| Код | public class Test { private static final String STRING = "Привет пока Hello hell"; public static void main(String[] args){ System.out.println(STRING); System.out.println(); test1("(?s)[пh]"); test1("(?i)[пh]"); System.out.println(); test2("(?s)[пh]"); test2("(?i)[пh]"); System.out.println(); test3("(?s)[пh]"); test3("(?i)[пh]"); System.out.println(); test4("(?s)[пh]"); test4("(?i)[пh]");
} public static void test1(String regexp){ Matcher matcher = Pattern.compile(regexp,Pattern.UNICODE_CASE ) .matcher(STRING); System.out.println(matcher.replaceAll("#")); } public static void test2(String regexp){ Matcher matcher = Pattern.compile(regexp) .matcher(STRING); System.out.println(matcher.replaceAll("#")); } public static void test3(String regexp){ Matcher matcher = Pattern.compile(regexp,Pattern.CASE_INSENSITIVE|Pattern.UNICODE_CASE ) .matcher(STRING); System.out.println(matcher.replaceAll("#")); } public static void test4(String regexp){ Matcher matcher = Pattern.compile(regexp,Pattern.CASE_INSENSITIVE ) .matcher(STRING); System.out.println(matcher.replaceAll("#")); } }
|
вот отрабокта класса:
Привет пока Hello hell
#ривет #ока Hello #ell #ривет #ока #ello #ell
Привет #ока Hello #ell Привет #ока #ello #ell
#ривет #ока #ello #ell #ривет #ока #ello #ell
Привет #ока #ello #ell Привет #ока #ello #ell
Каким раком надо использовать Pattern, чтобы в итоге получилась такая строка:
Привет #ока Hello #ell
? |