Reputation: 2482
Given a keyword Product data sheet
how can I extract 3rd line only after that match.
For example, given below data, output should be XB4BW84M5
Product data sheet
Characteristics
XB4BW84M5
I have tried (Product data sheet)\r\n(.*?)(^.*\r\n){3}
but, that is to find something preceeded by 2 lines then the key word but, it extracts all 3 lines I need the 3rd only
Upvotes: 1
Views: 1913
Reputation: 37337
Use this pattern: (?<=Product data sheet)\r?\n.+\r?\n(.+)
Explanation:
(?<=Product data sheet)
- assert that what's preceding is Product data sheet
If assertion is true, then it matches new line character with \r?\n
, then matches whole line with .+
, which is "match one or more of any characters", then again, in order to match newline I used \r?\n
and then used (.+)
to store in capturing group second line after desired string.
Upvotes: 4