私は正規表現を使用してJavaでプログラムを書いていますが、文Given string;には多くの構造があります。「ドクター・アーメド・モハメドのための本「学習Java」」。または「最高のタイトル: ahmed mohamed の Java の学習」など...,
つまり:
(本) は [本またはテキスト: または (テキスト)] の場合があります。
(for doctor ) は [ for author または for or for for doctor ] の場合があります。
出力:
(book) の前後と (doctor の場合) の前にある単語を抽出して、タイトルと名付けたいと思います。(doctor の場合) の後に任意の単語を抽出し、Author という名前を付けます。
String inputtext = "book 'learning java' for doctor ahmed mohamed";
Pattern p = Pattern.compile("(?<=(book| the book| \\( . \\)|\\:)) .*? (?=(for doctor| for| for author))");
Matcher m = p.matcher(inputtext);
if (m.matches()) {
String author = m.group(1).trim();
String bookTitle = m.group(2).trim();
System.out.println("Title is : " + author);
System.out.println("Author is : " + bookTitle);