Regular expression : extract text from middle of line

I need to extract the text from below sample as follows –
Sample text –

Link speed type is OK, link duplex type is DOWN
Unknown-speed mode, Link speed type is OK, Flow-control is disabled
Link speed type is OK, link duplex type is DOWN, Flow-control is disabled

From this i want to extract the line starting with Link speed(It can be on start of line or in middle line) upto the Flow-Control…(this part can or cannot be present).

So the desired output would be like this –

Link speed type is OK, link duplex type is DOWN
Link speed type is OK
Link speed type is OK, link duplex type is DOWN

means first and third line full and from second line only link speed part excluding comma and Flow-control part..
I tried few ways..

^s*(?:.*,)?s*(Link speed.*)

Problem – this selects 2nd line till the end.

^s*(?:.*,)?s*(Link speed.*(?=W*Flow-control))

It does not select the first line which does not have flow-control in it.


Source: regex

Leave a Reply