Extracting strings between two Regex expression -
i have string (log file), want extract text between 2 strings (multiple instances).
this text have:
++ planning iterations of demand 337 ++ ========================================= demand: 337 event: 1189.001 object/state: 7058/0 tier: 0 start: 1608130700 duration: 90 at: 19-7-2016 16:19:36 demand: 337 event: 1190.001 object/state: 7059/0 tier: 0 start: 1608130830 duration: 330 at: 19-7-2016 16:19:36 demand: 337 event: 1191.001 object/state: 7060/0 tier: 0 start: 1608140000 duration: 360 at: 19-7-2016 16:19:36 ++ event plan of demand 337 ++ =============================== event_time(1242.001,1,1609070800,1609071430) event_time(1241.001,1,1609060800,1609061430) event_time(1240.001,1,1609050800,1609051430) ++ planning iterations of demand 174 ++ ========================================= demand: 174 event: 212.001 object/state: 6948/0 tier: 0 start: 1609010800 duration: 390 at: 19-7-2016 16:19:38 demand: 174 event: 213.001 object/state: 6949/0 tier: 0 start: 1609020800 duration: 390 at: 19-7-2016 16:19:38 ++ event plan of demand 174 ++ =============================== event_time(213.001,1,1609020800,1609021430) event_time(212.001,1,1609010800,1609011430)
i want every thing between
++ planning iterations of demand 337 ++ =========================================
and
++ event plan of demand 174 ++ ===============================
the results expect is:
demand: 337 event: 1189.001 object/state: 7058/0 tier: 0 start: 1608130700 duration: 90 at: 19-7-2016 16:19:36 demand: 337 event: 1190.001 object/state: 7059/0 tier: 0 start: 1608130830 duration: 330 at: 19-7-2016 16:19:36 demand: 337 event: 1191.001 object/state: 7060/0 tier: 0 start: 1608140000 duration: 360 at: 19-7-2016 16:19:36 demand: 174 event: 212.001 object/state: 6948/0 tier: 0 start: 1609010800 duration: 390 at: 19-7-2016 16:19:38 demand: 174 event: 213.001 object/state: 6949/0 tier: 0 start: 1609020800 duration: 390 at: 19-7-2016 16:19:38
i tried solved myself , got point, returns first match end of text.
this regular expression used:
demand:(?s)(.*)[+][+]
i think best way find demand: ...
lines.
you following regex:
(?m)demand:\s+.*$
this regex finds 1 line of type want. need use function in whatever language/library use searches strings match regex in text.
the (?m)
@ beginning sets m
option, stands multiline, $
match end of line , not end of entire txt.
after regex quite simple. searches demmand:
followed @ least 1 space, until end of line. regex default doesn't expand .
search across lines, , limited line scans. had expanded (like using option s
inside preceding parenthesis) have had update regex (?m)demand:\s+.*?$
- add ?
symbol make search until end of line non greedy.
Comments
Post a Comment