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;
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
add a comment
|
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
1
What is your regex tool or language?
– Tim Biegeleisen
Mar 28 at 10:24
add a comment
|
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
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
regex
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
add a comment
|
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
add a comment
|
1 Answer
1
active
oldest
votes
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
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 replaces*withr?nat least.
– revo
Mar 28 at 10:38
1
@fadytaher Using1as substitution pattern
– Michał Turczyn
Mar 28 at 11:50
|
show 4 more comments
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 replaces*withr?nat least.
– revo
Mar 28 at 10:38
1
@fadytaher Using1as substitution pattern
– Michał Turczyn
Mar 28 at 11:50
|
show 4 more comments
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
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 replaces*withr?nat least.
– revo
Mar 28 at 10:38
1
@fadytaher Using1as substitution pattern
– Michał Turczyn
Mar 28 at 11:50
|
show 4 more comments
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
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
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 replaces*withr?nat least.
– revo
Mar 28 at 10:38
1
@fadytaher Using1as substitution pattern
– Michał Turczyn
Mar 28 at 11:50
|
show 4 more comments
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 replaces*withr?nat least.
– revo
Mar 28 at 10:38
1
@fadytaher Using1as 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
|
show 4 more comments
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
What is your regex tool or language?
– Tim Biegeleisen
Mar 28 at 10:24