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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:19:08+00:00 2026-05-17T15:19:08+00:00

I am trying to extract blocks of JSON data from a data stream in

  • 0

I am trying to extract blocks of JSON data from a data stream in the following format:

    Some-Header-Name:Value
    Content-Length:Value
    Some-Other-Header:Value

    {JSON data string of variable length}

The stream contains many instances of the above pattern and the length of JSON data in each instance is different, as indicated by the preceeding Content-Length header.

I wish to create a Regex that matches each of the content length header values and uses it to match the associated content block. I envisage something like this …

    Content-Length:(?<LENGTH>\d+).*?\r\n\r\n(?<CONTENT>.{$<LENGTH>})

… but I’m not sure how to specify the quantifier for the CONTENT group as a dynamic value.

Note: although the headers are on separate lines and the content is separated from the headers by a blank line, there is no linefeed after the content, so it is not possible to use this to determine the end of content.

Any suggestions would be appreciated.

Thanks,
Tim

  • 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-17T15:19:08+00:00Added an answer on May 17, 2026 at 3:19 pm

    Regular expressions match strings, not numbers, and therefore they can’t take a part of the string, convert it to a number, and reapply it within the same regex.

    You’d have to do it in several steps:

    1. Match the header, extract the length value
    2. Build a new regex like @"(?<HEADER>...)(?<CONTENT>.{" + length + "})"
    3. Reapply that regex and extract the contents.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to extract the domain name from a string in C#. You don't
Im trying to extract a line from wget's result but having trouble with it.
I am trying to extract a table of values from an excel (2003) spreadsheet
I'm trying to extract all matches from a EBML definition, which is something like
I'm trying to parse a html page and extract 2 values from a table
I am trying to extract a gif image embedded as a resource within my
I am trying to extract a certain part of a column that is between
I'm trying to extract the attributes of a anchor tag ( <a> ). So
I'm trying to write a log parsing script to extract failed events. I can
I am trying to write a Java class to extract a large zip file

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.