我使用正則表達式用Java編寫的程序,我有很多結構的句子 鑑於串; 「書」學習Java爲醫生艾哈邁德·穆罕默德「。或「最好的標題:艾哈邁德·穆罕默德·學習java」,等等......,寫正則表達式來exteract從文本單詞的Java
這意味着:
(書)可能是[書或文字;或(文本)]。
(爲醫生)可以是[作者或用於或通過醫生。
輸出:
我想提取後(書)任何話之前(爲醫生),並把它命名爲標題。 並提取任何單詞後(爲醫生),並將其命名爲作者。
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);
那麼問題是什麼? – Thomas 2013-03-11 12:14:53
請回答這個問題 – 2013-03-11 15:30:03
如何在(模式p)和(模式pa)中編寫表達式? – 2013-03-11 15:35:04