package regexdemo;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class Regex6 {
public static void main(String[] args) {
//
//张三dwesdf3234李四fdfsdfef王五
//
//需求:将dwesdf3234和fdfsdfef替换成love
//需求:将字符串中名字分割
String str="张三dwesdf3234李四fdfsdfef王五";
//定义正则表达式
String regex1="[\\w&&[^_]]+";
//需求1;
//replaceAll:按照正则表达式进行替换
String s1 = str.replaceAll(regex1, "love");
System.out.println(s1);
//需求2:
//spilt:按照正则表达式进行切割
String[] arr = str.split(regex1);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
/*System.out.println(s1);
//获取正则表达式对象
Pattern p = Pattern.compile(regex1);
//获取文本匹配器对象
Matcher m = p.matcher(str);
while(m.find()){
String s = m.group();
System.out.println(s);*/
}
}