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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:42:32+00:00 2026-05-24T01:42:32+00:00

I am trying to use regex to parse out some lines from text read

  • 0

I am trying to use regex to parse out some lines from text read in from a file. I know this could be done by reading in the file, line-by-line, but I like the elegance in capturing all the relevant bits of info in a single regex match.

The example file contents:

---
title: a title
layout: page
---

here's some text
================

this will be blog post content.

I am trying to produce a regex match that will return 2 groups: the data in-between the “—” lines, and all of the data after the 2nd “—” line. Here is the regex string I have come up with, and I am having an issue with it:

re.match('---\n(.*?)\n---\n(.*)', content, re.S)

This seems to work well, except when dealing with unix vs windows line-endings. Is there a way to allow this regex to match a \r if it’s present, too? It works with the unix, which is just \n I believe.

Also, if you think this regex could be improved, I’m open to suggestions.

  • 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-24T01:42:33+00:00Added an answer on May 24, 2026 at 1:42 am

    The sequence (\r\n|\r|\n) will match all ‘normal’ line endings (Windows, old Mac, and *nix, respectively).

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

Sidebar

Related Questions

I am trying to parse about 20 million lines from a text file and
I'm trying to figure out how to better parse lines of text that have
I am trying to parse a 500K text file. This is more of a
I'm trying to write a regex that will parse out the directory and filename
I'm trying to use Antlr for some text IDE-like functions -- specifically parsing a
I'm trying to sanitize/format some input using regex for a mixed latin/ideographic(chinese/japanse/korean) full text
I'm trying to use python to parse a log file and match 4 pieces
I am trying to parse a table in the form of a text file
I'm trying to parse some data out of a website. The problem is that
I'm trying to read a XML-RSS-Feed from a website. Therefore I use a async

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.