正则表达式
程序员文章站
2022-06-22 15:27:43
我们要解析一个html文档时可利用正则表达式取得标签内容 例子: 以从字符串中取出所有a标签的 id号和内容为例:
正则表达式
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-p3oIg7Y9-1609227416833)(C:\Users\春辉\Desktop\1608694702(1)].png)
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Q9zn7lJM-1609227416838)(C:\Users\春辉\Desktop\微信图片_20201223140732.png)]
正则表达式邮箱写法
public class MatchesDemo {
public static void main(String[] args) {
//邮箱的正则表达式
//[a-zA-Z0-9]+@[a-zA-Z0-9]+(\.[a-zA-Z]+)+
String email="fancq@tedu.cn";
String regex="[a-zA-Z0-9]+@[a-zA-Z0-9]+(\\.[a-zA-Z]+)+";
boolean match=email.matches(regex);
if (match){
System.out.println("是邮箱");
}else{
System.out.println("不是邮箱");
}
}
public static void main(String[] args) {
String str="abc123def456ghi";
//输入拆分的内容
String[] arr=str.split("[0-9]+");
//打印剩余数组数
System.out.println(arr.length);
//打印数组变量
System.out.println(Arrays.toString(arr));
String str="123asd456fgh789jkl";
//将数字0-9 替换 我那个去
str=str.replaceAll("[0-9]+","我那个去");
// 将字母a-z换成 数字8888
str=str.replaceAll("[a-z]+","8888");
System.out.println(str);//我那个去8888我那个去8888我那个去8888
public static void main(String[] args) {
//设置不让输出的 语言
String str="(wcnm|cbyld|wbd|gcl|djb)";
//接受说出的语言
String message="wcnm,大*,cbyld,王八蛋";
//正则表达式后 返回的语言
message=message.replaceAll(str,"***");
//打印
System.out.println(message);
8大类型与基本类之间的转换
*8个基本类型对应8个包装类
包装类出现的目的为了解决基本类型不能参与面向对象开发问题。
* */
public class IntegerDemo1 {
public static void main(String[] args) {
//基本类型转换为其对应的包装类
// Integer i1=Integer.valueOf(1);
//Integer i2=Integer.valueOf(1);
Integer i1=new Integer(1);
Integer i2=new Integer(1);
System.out.println(i1 == i2);
System.out.println(i1.equals(i2));
//z包装类转换为基本类型
int d=i1.intValue();
System.out.println(d);
double dou=i1.doubleValue();
System.out.println(dou);
}
}
eValue();
System.out.println(dou);
}
}
本文地址:https://blog.csdn.net/chuntiantaiyang/article/details/111920934
上一篇: Verizon将推出无人机数据流量套餐
下一篇: 铁乐学Python_day12_作业