有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (1) 个答案

  1. # 1 楼答案

    有多种选择。您可以使用边界(积分到@4castle),也可以使用向前看(积分到previous reply)和向后看

    以下是三个可行的选项:

    String input = "1,245.00";
    // look-ahead only
    Stream.of(input.split("(?=[,.])|(?<=[^\\d])")).forEach(System.out::println);
    System.out.println();
    // Boundary
    Stream.of(input.split("\\b")).forEach(System.out::println);
    System.out.println();
    // Mix of look-behind and look-ahead
    Stream.of(input.split("(?![\\d])|(?<=[^\\d])")).forEach(System.out::println);
    

    全部打印在一起:

    1
    ,
    245
    .
    00
    
    1
    ,
    245
    .
    00
    
    1
    ,
    245
    .
    00