我有一個文本,同時顯示某些輸出的字符串和數字的形式,並從那裏我有一個特定的文本如下。我想提取一段文字這使用正則表達式提取字符串的特定模式
這是一小塊我的內容
gjhsgdjhgfjhdgfjkhsdgfjkhgsdfk7868736876534
Pattern is:
(4,24,[5,96]) -> (1,14,[14,15]), that is: "Poland" -> "Poland"
(4,46,[36,39]) -> (1,14,[14,15]), that is: "Kim" -> "Kim"
fhafsdhjdfgjhdagfkhj66876493985694(hjiikfghkjfhg,98698)
(hhgjhgdfj,jhgkjdhgf)
從此我想要得到的輸出
"Poland" -> "Poland"
"Kim" -> "Kim"
"The police" -> "The city police on Friday"
我試過的代碼
Pattern p = Pattern.compile("(Pattern is:)\\((.*?)\\)");
Matcher m = p.matcher(str);
while(m.find())
{
System.out.println("fhkjsdfhkjsdh");
System.out.println(m.group(2));
}
@ user3580294「模式是:」是我要提取的文本片段。我的文本文件包含單詞「模式是」,我想在此之後提取內容 – chopss
「星期五」去哪兒了? –
@UlugbekUmirov發現我的錯誤。我編輯了我的問題 – chopss