Regular expression with lookghead

I can't get this regex to work.

The entry is as follows. Its valid on one line, but I inserted line breaks after each \ r \ n to make it easier to see, so whitespace is not required.

01-03\r\n
01-04\r\n
TEXTONE\r\n
STOCKHOLM\r\n
350,00\r\n            ---- 350,00 should be the last value in the first match
12-29\r\n
01-03\r\n
TEXTTWO\r\n
COPENHAGEN\r\n
10,80\r\n

This may continue with others 01-31 and 02-01, marking another new coincidence (these are dates).

I would like to have a total of 2 matches for this input. My problem is that I can’t understand how to look forward and match the start of a new match (the next two dates), but not include these dates in the first match. They must belong to the second match.

It's hard to explain, but I hope someone delivers me. This is what I got so far, but didn’t even close it:

(.*?)((?<=\\d{2}-\\d{2}))

I want a match:

1: 01-03\r\n01-04\r\nTEXTONE\r\nSTOCKHOLM\r\n350,00\r\n
2: 12-29\r\n01-03\r\nTEXTTWO\r\nCOPENHAGEN\r\n10,80\r\n

After that, I can easily split the columns with \ r \ n.

+3
4

:

(.+?)(?=\d{2}-\d{2}\\r\\n\d{2}-\d{2}|$)

Rubular

+2

?

(\d{2}-\d{2})\r\n(\d{2}-\d{2})\r\n(.*)\r\n(.*)\r\n(\d+(?:,?\d+))
+3
/
   \G
   (
      (?:
         [0-9]{2}-[0-9]{2}\r\n
      ){2}
      (?:
         (?! [0-9]{2}-[0-9]{2}\r\n ) [^\n]*\n
      )*
   )
/xg
+1

Why work so hard?

$string = q(01-03\r\n01-04\r\nTEXTONE\r\nSTOCKHOLM\r\n350,00\r\n12-29\r\n01-03\r\nTEXTTWO\r\nCOPENHAGEN\r\n10,80\r\n);
for (split /(?=(?:\d{2}-\d{2}\\r\\n){2})/, $string) {
   print join( "\t", split /\\r\\n/), "\n"
}

Conclusion:

01-03   01-04   TEXTONE STOCKHOLM       350,00
12-29   01-03   TEXTTWO COPENHAGEN      10,80`
0
source

Source: https://habr.com/ru/post/1790108/


All Articles