How to extract specific line after regex matchHow to replace plain URLs with links?Match all occurrences of a regexRegular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?How to negate specific word in regex?RegEx match open tags except XHTML self-contained tagsRegex match entire words onlyHow to print matched regex pattern using awk?Check whether a string matches a regex in JSregex that matches all lines that contains a specific word <python>

Why do sellers care about down payments?

Can the card disintegrate destroy creatures with indestructible?

Planar regular languages

I asked for a graduate student position from a professor. He replied "welcome". What does that mean?

Can I conceal an antihero's insanity - and should I?

Sol Ⅲ = Earth: What is the origin of this planetary naming scheme?

What are uses of the byte after BRK instruction on 6502?

What is the mathematical notation for rounding a given number to the nearest integer?

How to find a value that ensures 70% of population is above it

Why did it become so much more expensive to start a university?

Is there a reliable way to hide/convey a message in vocal expressions (speech, song,...)

Should I leave the first authorship of our paper to the student who did the project whereas I solved it?

Does my opponent need to prove his creature has morph?

The Planck constant for mathematicians

Finding the number of digits of a given integer.

Writing a love interest for my hero

I was promised a work PC but still awaiting approval 3 months later so using my own laptop - Is it fair to ask employer for laptop insurance?

What is and what isn't ullage in rocket science?

Diffraction of a wave passing through double slits

A simple problem about Rule

Linear Programming with additional "if-then"/"Default to zero" constraints?

Bash, import output from command as command

Why did they ever make smaller than full-frame sensors?

Is the Dodge action perceptible to other characters?



How to extract specific line after regex match


How to replace plain URLs with links?Match all occurrences of a regexRegular expression to match a line that doesn't contain a wordHow do you access the matched groups in a JavaScript regular expression?How to negate specific word in regex?RegEx match open tags except XHTML self-contained tagsRegex match entire words onlyHow to print matched regex pattern using awk?Check whether a string matches a regex in JSregex that matches all lines that contains a specific word <python>






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















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)rn(.*?)(^.*rn)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










share|improve this question





















  • 1





    What is your regex tool or language?

    – Tim Biegeleisen
    Mar 28 at 10:24

















1















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)rn(.*?)(^.*rn)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










share|improve this question





















  • 1





    What is your regex tool or language?

    – Tim Biegeleisen
    Mar 28 at 10:24













1












1








1


1






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)rn(.*?)(^.*rn)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










share|improve this question
















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)rn(.*?)(^.*rn)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







regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:28









Michał Turczyn

20.8k13 gold badges24 silver badges42 bronze badges




20.8k13 gold badges24 silver badges42 bronze badges










asked Mar 28 at 10:21









ExorcismusExorcismus

80010 silver badges31 bronze badges




80010 silver badges31 bronze badges










  • 1





    What is your regex tool or language?

    – Tim Biegeleisen
    Mar 28 at 10:24












  • 1





    What is your regex tool or language?

    – Tim Biegeleisen
    Mar 28 at 10:24







1




1





What is your regex tool or language?

– Tim Biegeleisen
Mar 28 at 10:24





What is your regex tool or language?

– Tim Biegeleisen
Mar 28 at 10:24












1 Answer
1






active

oldest

votes


















4
















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.



Demo






share|improve this answer






















  • 1





    This still captures the 2nd line.

    – Tim Biegeleisen
    Mar 28 at 10:26











  • @TimBiegeleisen But you can use capturing group to get the desired result

    – Michał Turczyn
    Mar 28 at 10:27











  • @TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

    – Michał Turczyn
    Mar 28 at 10:30







  • 1





    A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

    – revo
    Mar 28 at 10:38






  • 1





    @fadytaher Using 1 as substitution pattern

    – Michał Turczyn
    Mar 28 at 11:50











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);














draft saved

draft discarded
















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395178%2fhow-to-extract-specific-line-after-regex-match%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









4
















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.



Demo






share|improve this answer






















  • 1





    This still captures the 2nd line.

    – Tim Biegeleisen
    Mar 28 at 10:26











  • @TimBiegeleisen But you can use capturing group to get the desired result

    – Michał Turczyn
    Mar 28 at 10:27











  • @TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

    – Michał Turczyn
    Mar 28 at 10:30







  • 1





    A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

    – revo
    Mar 28 at 10:38






  • 1





    @fadytaher Using 1 as substitution pattern

    – Michał Turczyn
    Mar 28 at 11:50
















4
















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.



Demo






share|improve this answer






















  • 1





    This still captures the 2nd line.

    – Tim Biegeleisen
    Mar 28 at 10:26











  • @TimBiegeleisen But you can use capturing group to get the desired result

    – Michał Turczyn
    Mar 28 at 10:27











  • @TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

    – Michał Turczyn
    Mar 28 at 10:30







  • 1





    A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

    – revo
    Mar 28 at 10:38






  • 1





    @fadytaher Using 1 as substitution pattern

    – Michał Turczyn
    Mar 28 at 11:50














4














4










4









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.



Demo






share|improve this answer















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.



Demo







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 28 at 10:41

























answered Mar 28 at 10:25









Michał TurczynMichał Turczyn

20.8k13 gold badges24 silver badges42 bronze badges




20.8k13 gold badges24 silver badges42 bronze badges










  • 1





    This still captures the 2nd line.

    – Tim Biegeleisen
    Mar 28 at 10:26











  • @TimBiegeleisen But you can use capturing group to get the desired result

    – Michał Turczyn
    Mar 28 at 10:27











  • @TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

    – Michał Turczyn
    Mar 28 at 10:30







  • 1





    A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

    – revo
    Mar 28 at 10:38






  • 1





    @fadytaher Using 1 as substitution pattern

    – Michał Turczyn
    Mar 28 at 11:50













  • 1





    This still captures the 2nd line.

    – Tim Biegeleisen
    Mar 28 at 10:26











  • @TimBiegeleisen But you can use capturing group to get the desired result

    – Michał Turczyn
    Mar 28 at 10:27











  • @TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

    – Michał Turczyn
    Mar 28 at 10:30







  • 1





    A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

    – revo
    Mar 28 at 10:38






  • 1





    @fadytaher Using 1 as substitution pattern

    – Michał Turczyn
    Mar 28 at 11:50








1




1





This still captures the 2nd line.

– Tim Biegeleisen
Mar 28 at 10:26





This still captures the 2nd line.

– Tim Biegeleisen
Mar 28 at 10:26













@TimBiegeleisen But you can use capturing group to get the desired result

– Michał Turczyn
Mar 28 at 10:27





@TimBiegeleisen But you can use capturing group to get the desired result

– Michał Turczyn
Mar 28 at 10:27













@TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

– Michał Turczyn
Mar 28 at 10:30






@TimBiegeleisen Then this would become impossible to achieve, as it would require positive lookbehind of variable length, which is only allowed in .NET. Moreover, what regex tools? I don't know any that doesn't support capturing group.

– Michał Turczyn
Mar 28 at 10:30





1




1





A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

– revo
Mar 28 at 10:38





A wrong match is likely if third line doesn't exist. You'd better replace s* with r?n at least.

– revo
Mar 28 at 10:38




1




1





@fadytaher Using 1 as substitution pattern

– Michał Turczyn
Mar 28 at 11:50






@fadytaher Using 1 as substitution pattern

– Michał Turczyn
Mar 28 at 11:50









Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















draft saved

draft discarded















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55395178%2fhow-to-extract-specific-line-after-regex-match%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?