---
title: "处女apk纠结过的技术点<3>"
author: "ping8080"
date: "2011-02-28T11:57:12Z"
tags: []
categories: ["移动开发"]
slug: "apk-3"
draft: false
lastmod: "2011-02-28T11:57:12Z"
id: 933298
url: "https://ping8080.iteye.com/blog/933298"
---

正则表达式

android下使用正则表达式，和java没有多大的区别，搬过来直接照样，主要的难点是匹配方式比较难下手：

我这个例子是分组取值解析一个html网页，需注意:正则表达式不能识别回车 和换行 所有要用空格替换掉.

public static String getUserId(String str){  
  str = str.replaceAll(String.valueOf((char) 10), " ");//替换回车  
  str = str.replaceAll(String.valueOf((char) 13), " ");//替换空格  
  String regEx="var\\\\sbasicPanel\\\\s=\\\\snew\\\\sExt.Panel.\*?patient.userId.\*?value:'(.\*?)'";//.\*?代表0个以上的任意字符 ，？代表截断点  
  Pattern pattern=Pattern.compile(regEx);  
  Matcher matcher=pattern.matcher(str);  
  if(matcher.find()){  
   return matcher.group(1);//取第一个匹配的 若使group()的话 那是获取所有  
  }  
  return null;  
 }