正则表达式

// @@111611!@
	// adf@@1119911!@
	// @@33633!@
	// adf@@1119911!@22222@@339933!@
	// adf@@1119911!@22222@@339933!@4444
	@Test
	public void t8() {
		
		String start = "'json':'{";
		String end = "}','md5'";
		String middle = "'+";
		StringBuffer sb = new StringBuffer();
		StringBuffer sb2 = new StringBuffer();
		word = "adf@@111611!@22222@@33633!@4444";
		String regEx = "@@.*?(6).*?!@"; // 表示一个或多个@
		Pattern pat = Pattern.compile(regEx);
		Matcher m = pat.matcher(word);
		StringBuffer sb3 = new StringBuffer();
		while (m.find()) {
			System.out.println(m.group());
			m.appendReplacement(sb3, "");
			sb3.append(m.group().replace("6", "99"));
			System.out.println(sb3.toString());
		}
		System.out.println(m.appendTail(sb3));
	}

@Test
		public void t9() {
			
			String regEx = "\\{'birthday':.*?(').*?\\}"; // 表示一个或多个@
			Pattern pat = Pattern.compile(regEx);
			Matcher m = pat.matcher(word);
			StringBuffer sb3 = new StringBuffer();
			while (m.find()) {
				System.out.println(m.group());
				System.out.println(m.groupCount());
				m.appendReplacement(sb3, "");
				sb3.append(m.group().replace("'", "\""));
				System.out.println(sb3.toString());
			}
			System.out.println(m.appendTail(sb3));
		}


String regEx = "'json':'\\{'.*?(').*?'\\}";
					Pattern pat = Pattern.compile(regEx);
					Matcher m = pat.matcher(json);
					StringBuffer sb = new StringBuffer();
					while (m.find()) {
						m.appendReplacement(sb, "");
						sb.append("'json':'").append(m.group().replaceFirst("'json':'", "").replace("'", "\\'"));
					}
					System.out.println(m.appendTail(sb));

你可能感兴趣的:(正则表达式)