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

  • Home
  • SEARCH
  • 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 458689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:41:48+00:00 2026-05-12T22:41:48+00:00

I want to match the following: a zero length line, with the match continuing

  • 0

I want to match the following: a zero length line, with the match continuing across lines of non-zero length until a particular string is matched in a line. E.g: the match starts with a zero length line and continues until STOP is reached:

Some random text I don't care about

The match starts at the beginning of this line
The match continues across this line
The match stops here STOP more
text I don't care about

Any suggestions?

Thanks

  • 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-12T22:41:49+00:00Added an answer on May 12, 2026 at 10:41 pm

    This should do it:

    (?ms)^[ \t]*+$\s*+((?:(?!STOP).)*+)
    

    A little demo:

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    public class Main { 
        public static void main(String[] args) {
            String text = "Some random text I don't care about"      + "\n" +
                    ""                                               + "\n" +
                    "The match starts at the beginning of this line" + "\n" +
                    "The match continues across this line"           + "\n" +
                    "The match stops here STOP more"                 + "\n" +
                    "don't care about"                               + "\n" +
                    ""                                               + "\n" +
                    ""                                               + "\n" +
                    ""                                               + "\n" +
                    "foo"                                            + "\n" +
                    "barSTOP"                                        + "\n" +
                    "text I don't care about";
            Matcher m = Pattern.compile("(?ms)^[ \t]*+$\\s*+(?:(?!STOP).)*+").matcher(text);
            while(m.find()) {
                System.out.println("match ->"+m.group()+"<-");
            }
        }
    }
    

    which will output:

    match ->
    The match starts at the beginning of this line
    The match continues across this line
    The match stops here <-
    match ->
    
    
    foo
    bar<-
    

    A small explanation:

    (?ms)               # enable mutli-line and dot-all
    ^[ \t]*+$           # match and empty line
    \s*+                # match the line break
    (                   # start group 1
      (?:(?!STOP).)     #   if the string 'STOP' cannot be seen, match any character
      *+                #   match the previous zero or more times (possessively)
    )                   # stop group 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to match and modify part of a string if following conditions are
If I want to match() a string with the following pattern: 12345678_12345678 What would
I have the following line: hshd household 8/29/2007 LB I want to match anything
I want to match the following line with the regex in sed: db=connect_str=DBI:SQLAnywhere:ENG=ABC1_hostname12;DBN=ABC12;UID=USERID;PWD=passwd123;LINKS=tcpip{host=10.11.12.13:1234} The
i want to match 12,345 in the following string: adf99fgl12,345qsdfm34 In general case, i
I want to write a regular expression that will match the following string a
Consider the following string: ab(cd.xz) e(ab(fg).xz)) ab(hi.xz) I want to match every substring that
Well my question is simple, I want to match a string with following attributes
I want to match the following: any string which contains any character, except /
I want to match every single number in the following string: -0.237522264173E+01 0.110011117918E+01 0.563118085683E-01

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.