我通过 HttpGet 获得响应。在 getEntity().getContent() 之后我得到了 HTML 页面的代码,然后将这个页面转换为 String pageHTML。
我需要使用正则表达式匹配pageHTML,然后获取结果。
我已经创建了正则表达式。
如果正则表达式只是返回一个值,如何创建? 如果正则表达式只返回n个值,如何创建?
最佳答案
您可以使用组从正则表达式接收多个值。参见 this了解详情。
Pattern datePatt = Pattern.compile("([0-9]{2})/([0-9]{2})/([0-9]{4})");
Matcher m = datePatt.matcher(dateStr);
if (m.matches()) {
int day = Integer.parseInt(m.group(1)); // get values inside the first (..)
int month = Integer.parseInt(m.group(2)); // get values inside the second (..)
int year = Integer.parseInt(m.group(3)); // get values inside the third (..)
}
关于java - Android中使用正则表达式处理字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13967612/