Всем доброго времени суток! Прошу помощи)) Валидатор не пропускает мой код, мое регулярное выражение на тестовом файле отбирает все слова, содержащие цифры и исключает из отбора просто цифры.
Ниже тестовый файл:
"1D regular expression, regex or regexp1
(sometimes called a rational expressi4on is a sequence of
characters that define a search pattern. Usually such patterns
are used by string searching algorithms for "find" or "find and replace" operations on strings,
or for input validation. It is a technique developed in theoretical computer science and formal language theory.
The 1concept arose in the 1950s when the American mathematician Stephen Cole Kleene formalized the
description of a regular language. The concept came into common use with Unix text-processing utilities.
Since the 1980s different syntaxes for writing regular expressions exist, one being the POSIX stan98dard
and another, widely used, being the Perl syntax.
k9
0ll9
12345432
Regular expressions are used in search engines, search and replace dialogs
of word processors and text editors, in text processing utilities such as sed and AWK and in lexical analysis.
Many programming languages provide regex capabilities either built-in or via libraries."
И результат отбора: "1D regexp1 expressi4on 1concept 1950s 1980s stan98dard k9 0kk9"
Подскажите пожалуйста в какую сторону смотреть?)) Спасибо!
package com.javarush.task.task19.task1923;
/*
Слова с цифрами
*/
import java.io.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class Solution {
public static void main(String[] args) {
String fileName1 = args[0];
String fileName2 = args[1];
try(BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName1));
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileName2))) {
StringBuilder lines = new StringBuilder();
while (bufferedReader.ready()) {
lines.append(bufferedReader.readLine() + " ");
}
String line = Stream.of(lines.toString()
.split("\\s"))
.filter(s -> s.matches("((\\p{L}+\\d+)|(\\d+\\p{L}+))[\\p{L}\\d]*"))
.collect(Collectors.joining(" "));
bufferedWriter.write(line);
} catch (IOException e) {
}
}
}