发布网友 发布时间:1天前
共5个回答
热心网友 时间:1天前
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ttts {
public static void main(String... strs) {
String str = "VVV4BC3233BBB";
System.out.println(getStrings(new StringBuilder(),str));
}
public static String getStrings(StringBuilder sb,String str) {
if (str == null)return "";
if (str.equals(""))return sb.toString();
Pattern p = Pattern.compile("[a-zA-Z]*[0-9]*");
Matcher m = p.matcher(str);
if (m.find()) {
String group = m.group();
sb.append(group);
String subStr = str.substring(group.length());
Pattern pattern = Pattern.compile(".*\\d+.*");
if (pattern.matcher(subStr).matches()) {
getStrings(sb,str.substring(group.length()));
}
}
return sb.toString();
}
}
热心网友 时间:1天前
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Test {
public static boolean check(String str,String regex){
Pattern p=Pattern.compile(regex);
Matcher m=p.matcher(str);
boolean result =m.find();
return result;
}
public static String getSubString(String s){
int m = -1;
int length = s.length();
if(s!=null&&!"".equals(s.trim())){
for(int i=length-1;i>0;i--){
char c = s.charAt(i);
boolean b = check(c+"", "\\d");
if(b){
m = i;
break;
}
}
}
String result = "";
if(m!=-1){
result = s.substring(0,m+1);
}
return result;
}
public static void main(String args[]) throws IOException {
String s = "AS12VV33BV";
System.out.println(getSubString(s));
}
}
热心网友 时间:1天前
你是想用一个正则表达式找出来?
热心网友 时间:1天前
好复杂的说
热心网友 时间:1天前
^/0-9/g