-1
我想之間(不包括)的字符串:ALT =「和‘ 這裏是我的代碼一個小樣本:我如何進行正則表達式匹配(非包含)?
Pattern p2 = compile("alt=\"(.*?)\");
Matcher m2 = p2.matcher(result);
while (m2.find()) {
names.add(m2.group());
}
的輸出,例如:ALT =’哈利·波特」
當我想輸出只是:哈利波特
使用'compile(「alt = \」(。*?)\「」)'和'm2.group(1)',但是要解析HTML,你最好使用一些HTML解析器。 –
或者你可以使用lookaround:'(?<= alt =「)。*?(?=」)'並避免處理捕獲組。但是你應該真的使用HTML解析器。 – Amadan
輝煌@wiktor謝謝 –