Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6223635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:31:28+00:00 2026-05-24T08:31:28+00:00

Hello I need to find regex that would get middle section of this text:

  • 0

Hello I need to find regex that would get middle section of this text:

# Command // first line with symbol character 

First line of interest
Second line of interest
\n
Third line of interest
\n
\n // I am not interested in trailing new lines.

How could I get text starting with First line of interest and ending wint third line of interest? Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:31:30+00:00Added an answer on May 24, 2026 at 8:31 am
    String test = "# Command\n\nFirst line of interest\r\nSecond line of interest\n\r\nThird line of interest\r\n\n";
    System.out.printf("%n>>%s<<%n", test);
    
    Pattern p = Pattern.compile("^(?!#).+(?:[\r\n]+.+)*", Pattern.MULTILINE);
    Matcher m = p.matcher(test);
    if (m.find())
    {
      System.out.printf("%n>>%s<<%n", m.group());
    }
    

    output:

    >># Command
    
    First line of interest
    Second line of interest
    
    Third line of interest
    
    <<
    

     

    >>First line of interest
    Second line of interest
    
    Third line of interest<<
    

    The match starts at the beginning (^ in MULTILINE mode) of the first line that does not start with a hash symbol ((?!#)), but does contain characters other than line separators (.+, not .*).

    [\r\n]+ matches one or more line separators, whether they be the Unix (\n), DOS (\r\n), or older-Mac (\r) style of separator. You should always be prepared to handle any or all of the different line separators, no matter what platform your code is running on.

    (?:[\r\n]+.+)*, then, matches zero or more additional lines, without matching any trailing line separators.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello , I have text and I need to find in it a string
hello i need to find the decomposition of this matrix Matrix but as you
Eg :a=[[hello, world], [good, lord], [hello, lord]] I need to find and record the
Hello I need to do something like this: UPDATE tbl SET pozn=CONCAT(pozn, '+attach_str+') WHERE
Hello guys i need to capture the output of an external command, herefore I
For example, we have this xml: <x> <y>some text</y> <y>[ID] hello</y> <y>world [/ID]</y> <y>some
I need help while trying to spin articles. I want to find text and
Hello everyone I would have a value for the need to save every time
Hello i have the this problem, i need your help to figure out what
In Clear Case, I need to find all Versions that checked-in by me In

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.