---
title: "Java 正则表达式一例"
author: "wwbutton"
date: "2008-09-23T02:34:05Z"
tags: []
slug: "java"
draft: false
lastmod: "2008-09-23T02:34:05Z"
id: 245695
url: "https://button.iteye.com/blog/245695"
---

<u>______</u> 替换<u></u> 之间的_ 为等量的String。
public class TestRegStr {
	public static void main(String args) {
		System.out.println("-----------");
		String s1 = "ftggh <u>__________</u>faadf<u>_</u>grgsfdgsgsfg   <u>_____</u>  dfasf<u>_____ ";
		
		Matcher m1 = Pattern.compile("(<u>)(_*)(_)(*)(</u>)").matcher(s1);
		
		while (m1.find()) {
			//System.out.println(m1.group() + "\t");
			s1 = m1.replaceAll("$1$2X$4$5");
			//System.out.println(s1);
			
			m1.reset(s1);
		}
		System.out.print(s1);
	}
}