No BB,直接上代码示例:
String str = "沙比修仙传第7279章56回";
String str = "https://www.java.com/id65536/";
String str = "https://www.jj.com/notebooks/28048652/notes/53919505";
String regex = "\\d*";
Pattern pattern = Pattern.compile(regex);
Matcher match= pattern.matcher(str);
while (match.find()) {
if (!"".equals(match.group()))
System.out.println("出来吧,数字们: " + match.group());
}
下面提供更多的方法
// 判断一个字符串是否都为数字
public boolean isDigit(String strNum) {
return strNum.matches("[0-9]{1,}");
}
// 判断一个字符串是否都为数字
public boolean isDigit(String strNum) {
Pattern pattern = Pattern.compile("[0-9]{1,}");
Matcher matcher = pattern.matcher((CharSequence) strNum);
return matcher.matches();
}
//截取数字
public String getNumbers(String content) {
Pattern pattern = Pattern.compile("\\d+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 截取非数字
public String splitNotNumber(String content) {
Pattern pattern = Pattern.compile("\\D+");
Matcher matcher = pattern.matcher(content);
while (matcher.find()) {
return matcher.group(0);
}
return "";
}
// 判断一个字符串是否含有数字
public boolean HasDigit(String content) {
boolean flag = false;
Pattern p = Pattern.compile(".*\\d+.*");
Matcher m = p.matcher(content);
if (m.matches()) {
flag = true;
}
return flag;
}
判断字符串是否已数字开头
String str = "a40###2";
System.out.println(str.matches("^\\d+?.*$"));
我们从网上爬下来的文件很多时候都是带着<br>之类的格式化标签
content = content.replace('<br/>', '\n')
帮到客官了没?打个赏再走吧....哎,哎,客官别走啊.....
QQ群放这里:578060039 我发了,你随意
打完收工
网友评论