昆明智能网站推广价格,wordpress移动端不显示图片,一键免费建站,招牌设计创意门头1.验证电子邮件格式是否合法
规定电子邮件规则为
1.只能有一个
2. 前面是用户名,可以是a-z A-Z 0-9 _ - 字符
3. 后面是域名#xff0c;并且域名只能是英文字母#xff0c;比如sohu.com或者tsinghua.org.cn
4.写出对应的正则表达式#xff0c;验证输入的字符串是否为满…1.验证电子邮件格式是否合法
规定电子邮件规则为
1.只能有一个
2. 前面是用户名,可以是a-z A-Z 0-9 _ - 字符
3. 后面是域名并且域名只能是英文字母比如sohu.com或者tsinghua.org.cn
4.写出对应的正则表达式验证输入的字符串是否为满足规则
public class Homework01 {public static void main(String[] args) {// String content 643013242qq.com;// String content yinhai14qq.com;String content yinhai14qq.com.;String regStr [\\w_-]([a-zA-Z]\\.)[a-zA-Z];if(content.matches(regStr)){System.out.println(匹配成功);}else{System.out.println(匹配失败);}}
}2.要求验证是不是整数或者小数
提示:这个题要考虑正数和负数
比如:123 -345 34.89 -87.9 -0.01 0.45等
public class Homework02 {public static void main(String[] args) {String content -0.01;String regStr ^[-]?([1-9]\\d*|0)(\\.\\d)?$;if (content.matches(regStr)) {System.out.println(匹配成功 是整数或者小数);}else{System.out.println(匹配失败);}}
}3.对URL进行解析 public class Homework03 {public static void main(String[] args) {String content http://www.sohu.com:8080/abc/xxx/yyy/inde#$%x.htm;//因为正则表达式是根据要求来编写的所以如果需求需要的话可以改进.String regStr ^([a-zA-Z])://([a-zA-Z.]):(\\d)[\\w-/]*/([\\w.#$%])$;Pattern pattern Pattern.compile(regStr);Matcher matcher pattern.matcher(content);if(matcher.matches()) {//整体匹配, 如果匹配成功可以通过group(x), 获取对应分组的内容System.out.println(整体匹配 matcher.group(0));System.out.println(协议: matcher.group(1));System.out.println(域名: matcher.group(2));System.out.println(端口: matcher.group(3));System.out.println(文件: matcher.group(4));} else {System.out.println(没有匹配成功);}}
}