search

Home  >  Q&A  >  body text

正则表达式 - java获得一个String字符串中第一个数字的下标,并截取后面的6位和前面的地区

天蓬老师天蓬老师2810 days ago1552

reply all(5)I'll reply

  • ringa_lee

    ringa_lee2017-04-18 10:47:47

    String s = "杭州20170222ax";
    Pattern p = Pattern.compile("([0-9].{5,5})");
    Matcher m = p.matcher(s);
    m.find();
    System.out.println(m.group(1));

    reply
    0
  • 阿神

    阿神2017-04-18 10:47:47

    Traverse the string, str.charAt(i)>=48 && str.charAt(i)<=57 to determine the number, the first one that meets the requirements is the subscript

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-18 10:47:47

    System.out.println( new Scanner("宁波20170222呵呵22").useDelimiter("\D+").nextInt());

    reply
    0
  • 迷茫

    迷茫2017-04-18 10:47:47

    String s = "杭州20170222ax";
    char[] chars = s.toCharArray();
    for (int i = 0; i < chars.length; i++) {
        if (Character.isDigit(chars[i])) {
            System.out.println(s.substring(i, i + 6));
            break;
        }
    }

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-18 10:47:47

    http://www.cnblogs.com/androi...

    reply
    0
  • Cancelreply