Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- String text = "(слива) какие-то другие слова [яблоко], еще слова {груша}.";
- text = text.replaceAll("(\(|\[|\{)(.*?)(\)|\]|\})", "o0o0o0 $2 o1o1o1")
- .replaceAll("o1o1o1(.*?)o0o0o0","")
- .replaceAll("o1o1o1|o0o0o0","")
- .replaceAll("[^а-я]"," ")
- .replaceAll("\s+"," ");
- String[] fruits = text.split(" ");
- // [ , слива, яблоко, груша]
- ([а-я]+)|[[а-я]+]|{[а-я]+}
- String text = "(слива) какие-то другие слова [яблоко], еще слова {груша}.";
- Pattern pattern = Pattern.compile("[(\[{](.*?)[)\]}]");
- Matcher matcher = pattern.matcher(text);
- List<String> lst = new ArrayList<>();
- while (matcher.find()){
- lst.add(matcher.group(1));
- }
- System.out.println(lst);
- // => [слива, яблоко, груша]
Add Comment
Please, Sign In to add comment