Regex to find a string after the last colon

后端 未结 4 546
滥情空心
滥情空心 2021-01-28 08:34

Here is some sample input:

<210>   DW_AT_name        : (indirect string, offset: 0x55): double
    DW_AT_name        : (indirect string, offset:          


        
4条回答
  •  孤独总比滥情好
    2021-01-28 09:21

    Try the next:

    public static void main(String[] args) {
    
        String text = 
        "<210>   DW_AT_name        : (indirect string, offset: 0x55): double\n" + 
        "   DW_AT_name        : (indirect string, offset: 0x24): long int\n" + 
        "   DW_AT_name        : int";
    
        Pattern pattern = Pattern.compile("^.*DW_AT_NAME.*:\\s*([^:]+)$", 
                Pattern.CASE_INSENSITIVE);
    
        Scanner sc = new Scanner(text);
        while(sc.hasNextLine()) {
            String line = sc.nextLine();
            Matcher matcher = pattern.matcher(line);
            if (matcher.matches()) {
                System.out.println(matcher.replaceAll("$1"));
            }
        }
    
    }
    

    Output:

    double
    long int
    int
    

提交回复
热议问题