我正在嘗試使用下面列出的Java中的regex表達式來提取標簽內(nèi)的內(nèi)容。我一直在嘗試在標記中獲取段落上下文,但無法獲取它。 Some text without tags here... <question1> Paragraph 1... Paragraph 2... </question1> Some text without tags here... <question2> Paragraph 1... Paragraph 2... </question2> Some text without tags here...上面的標簽和內(nèi)容存儲在一個字符串變量中:stringToSearch。以下是我的代碼。Pattern p = Pattern.compile("<question1>(.*)</question1>");Matcher a = p.matcher(stringToSearch); System.out.print("\n Matching pattern...");// Search the patterns in string if (a.find()) { String codeGroup = a.group(1); System.out.format("'%s'\n", codeGroup); } 但是我無法獲得我懷疑是由于段落中可能出現(xiàn)新行的標簽。reg表達式而不是xml解析器的原因是由于我可能必須使用| question |的環(huán)境。| /問題| 或[[question]] [[/ question]]特殊符號。
添加回答
舉報
0/150
提交
取消