merry,girl,"110987654321"
tom,boy,"110987654322"
......
nnn行
......字符串分别包含 姓名,性别,身份证号码
现在只想获得每行的12位身份证号码  请问怎么用正则来截取
^[0-9]*[1-9][0-9]*$  // 表示取正整数

解决方案 »

  1.   

    取每一行的Strig值存至一个临时变量str中,如第一行获取后str = "merry,girl,110987654321" (我想应该是这个格式吧,而不是身份证两头都有引号)public class TestPath{
    public static void main(String []args){
    String str = "merry,girl,110987654321";
    String strArray [] = str.split(",");
    System.out.println(strArray[2]);
    }
    }
    //console:        110987654321
    //这种方法可以方便地提取所有的个人信息
    如果只是要最后的12位身份证号码,用下面这句话就可以了: System.out.println(str.substring(str.length() - 12, str.length()));
      

  2.   

    字符串截取substring(),不过不是用正则,呵呵~~
      

  3.   

    Pattern p = Pattern.compile("(?m)(?<=\")\\d{12}(?=\"$)")
    Matcher m = p.matcher(str);while (m.find()) {
    System.out.println(m.group());
    }
      

  4.   

    我的意思是想用正则判断 从字符串中 是数字的地方开始 向后截取12位
    substring是会用到的  只不过之前 需要判断一下
    姓名,性别,标点符号  都是不非空的
      

  5.   

    import java.util.regex.*;
    public class MyRegex {
    public static void main(String[] args) { String s="merry,girl,\"1109876543211111\"";
    s=s+"tom,boy,\"110987654322\" ";
    s=s+"Jim boy,IDCard=330523198707055013";
    Matcher m=Pattern.compile("\\d{12}").matcher(s);
    while (m.find()) {
    System.out.println(m.group());
    }
    }
    }