Java String.replaceAll 正则 .*表示所有字符


package test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.System.out;

public class testString {
public static void main(String arg [])
{
File file = new File("e:/widget config sample.xml");
FileInputStream fileInputStream;
BufferedReader reader = null;
try {
fileInputStream = new FileInputStream(file);
reader = new BufferedReader(new InputStreamReader(fileInputStream));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String xmlString = "";
String temp ;
try {
while((temp = reader.readLine())!=null )
{
xmlString += temp;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

out.println(xmlString);

String one = "abcdefghij.klmnop.qrstuvwxyz";
String two = "abc.defghij.klmnop.qrstuvwxyz";

xmlString = xmlString.replaceAll(".*.<entries ws='", "").replaceAll("' />.*</widgets>", "/ws/maps") ;
one = one.replaceAll("cde.*xy", "");
two = two.replaceAll("cde.*xy", "");

out.println(xmlString);
out.println(one);
out.println(two);

}
}


输出结果:

<?xml version="1.0" encoding="UTF-8"?><widgets> <widget name='employee'><datasource name='titles' type='map'><entries ws='http://www.sina.com'/></datasource></widget></widgets>
http://www.sina.com/ws/maps
abz
abc.defghij.klmnop.qrstuvwxyz


.表示任何字符, *表示0个-无穷个

[b]
replaceAll第一个参数是正则,split也是使用正则[/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值