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 7185441
In Process

The Archive Base Latest Questions

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

I would like to split the input as shown below. This input contains a

  • 0

I would like to split the input as shown below. This input contains a data type that has two parts. First part is the title, [XX] or [YY], and the other part is content (contents may contain \r\n\r\n or [XX] or [YY]). When the content finished, new data starts with \r\n\r\n[XX] OR \r\n\r\n[YY]:

[XX]\r\n
bla bla\r\n
bla bla\r\n
\r\n
[YY]\r\n
bla [XX] bla\r\n
bla bla\r\n
\r\n
[YY]\r\n
bla [YY] bla\r\n\r\n
bla bla\r\n
\r\n

I wrote two regex for catch and split this input, two of them are working but i think, they can be improved.

First: \[(XX|YY)\]\r\n((?:(?!\r\n\r\n\[(XX|YY)\]).)*)

Second (works good except the last data): \[(XX|YY)\]\r\n(.*?)(?=\r\n\r\n\[(XX|YY)\])

Both of them have “.*”, so they use lots of backtrack, is there any what to do this with [^]?

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-28T18:24:58+00:00Added an answer on May 28, 2026 at 6:24 pm

    I think both are fine and don’t have any more backtracking than necessary. You could anchor the title part to the start of the line, but that shouldn’t make much of a difference:

    (?m)^\[(XX|YY)\]\r\n((?:(?!\r\n\r\n\[(?:XX|YY)\]).)*)
    

    But perhaps your language already provides this functionality? It looks like you’re trying to parse a Windows-style configuration (.ini) file. For example, Python has the ConfigParser module for that.

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

Sidebar

Related Questions

I have a data set that looks like the below (the input). IR# CR#
I would like to use the .Net Regex.Split method to split this input string
I have a list of files that look like this: Input /foo/bar/baz/d4dc7c496100e8ce0166e84699b4e267fe652faeb070db18c76669d1c6f69f92.mp4 /foo/baz/bar/60d24a24f19a6b6c1c4734e0f288720c9ce429bc41c2620d32e01e934bfcd344.mp4 /bar/baz/foo/cd53fe086717a9f6fecb1d0567f6d76e93c48d7790c55e83e83dd1c43251e40e.mp4
I am writing many files to disk, and I would like to split them
I have a large source repository split across multiple projects. I would like to
Would like to make anapplication in Java that will not automatically parse parameters used
Would like to know the c# code to actually retrieve the IP type: Static
I wrote a code in which i would like to split a number of
I have two tab-delimited genome sequence files (SAM format), and I would like to
I have a large array in PHP. It contains strings that are split into

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.