我制作了一个JAVA程序,该程序试图找到与“ glow”一词成韵的单词。该程序可浏览“在佛兰德斯田里”这首诗,并输出任何带有韵律的词。为此,我试图让它查找以“ ow”结尾的单词,但是它没有显示押韵单词,而是显示“ ow”。综上所述,我希望程序查看这首诗,并使用查找,匹配或捕获方法显示所有带有“发光”押韵的单词。
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class juspractice {
public static void main(String[] args) {
Pattern p = Pattern.compile("ow", Pattern.CASE_INSENSITIVE);
String s = "In Flanders fields the poppies blow\n" +
"Between the crosses, row on row,\n" +
" That mark our place; and in the sky\n" +
" The larks, still bravely singing, fly\n" +
"Scarce heard amid the guns below.\n" +
"\n" +
"We are the Dead. Short days ago\n" +
"We lived, felt dawn, saw sunset glow,\n" +
" Loved and were loved, and now we lie,\n" +
" In Flanders fields.\n" +
"\n" +
"Take up our quarrel with the foe:\n" +
"To you from failing hands we throw\n" +
" The torch; be yours to hold it high.\n" +
" If ye break faith with us who die\n" +
"We shall not sleep, though poppies grow\n" +
" In Flanders fields ";
Matcher m = p.matcher(s);
if (m.find()) {
System.out.println(m.group());
}
}
}