单独的正则表达式组

时间:2018-05-30 19:32:35

标签: java regex regex-group

我有一个java正则表达式来获取(数字空间文本)值但是当我有一个新行时,该值没有分组,示例

正则表达式(\d{14}\s.*\n)

价值:

59105999000321 My value start
with new line number
12105999000343 AAAAAasasas asdasdasd
32105999000323 asdasxasxasx asdasd

https://regex101.com/中的组结果为:

Match 1
Full match  0-29    `59105999000321 My value start`
Group 1.    0-29    `59105999000321 My value start`
Match 2
Full match  51-87   `12105999000343 AAAAAasasas asdasdasd`
Group 1.    51-87   `12105999000343 AAAAAasasas asdasdasd`
Match 3
Full match  88-122  `32105999000323 asdasxasxasx asdasd`
Group 1.    88-122  `32105999000323 asdasxasxasx asdasd`

我有一个正则表达式,结果如下:

group 1 : 59105999000321 My value start
    with new line number

group 2: 12105999000343 AAAAAasasas asdasdasd

group 3: 32105999000323 asdasxasxasx asdasd

我希望

group 1 : 59105999000321 My value start with new line number 

group 2: 12105999000343 AAAAAasasas asdasdasd 

group 3: 32105999000323 asdasxasxasx asdasd

我在java中怎么做?

1 个答案:

答案 0 :(得分:1)

尝试正则表达式:\n*

Demo

说明: 由于要求是匹配以14位开头的行,因此在listdir

之后会添加相同的负前瞻