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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:40:23+00:00 2026-06-06T00:40:23+00:00

I’m currently working on a project in Ruby on Rails (in Eclipse) and my

  • 0

I’m currently working on a project in Ruby on Rails (in Eclipse) and my task is to split up a block of data into relevant parts using Regular Expressions.

I’ve decided to break up the data based on 3 parameters:

  1. The line must start with a capital letter (RegEx equivalent – /^[A-Z]/)
  2. It must end with a : (RegEx equivalent – /$":"/)

I would appreciate any help….The code I’m using in my controller is:

@f = File.open("report.rtf")  
@fread = @f.read  
@chunk = @fread.split(/\n/)

where @chunk is the array that will be created by the split and @fread is the data that is being split up (by new lines).

Any help will be appreciated, thanks a lot!

I cannot release the exact data but it goes basically by this (this is medically related)

Exam 1: CBW 8080

RESULT:

This report is dictated with specific measurement.
Please see the original report.

COMPARISON: 1/30/2012, 3/8/12, 4/9/12

RECIST 1.1:
BLAH BLAH BLAH

The ideal output would be an array that says:

["Exam 1:", "CBW 8080", "RESULT", "This report is dictated with specific measurement. Please see the original report.", "COMPARISON:", "1/30/2012, 3/8/12, 4/9/12", "RECIST 1.1:", "BLAH BLAH BLAH"]

PS I’m just using \n as a placeholder until I get it working

  • 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-06-06T00:40:24+00:00Added an answer on June 6, 2026 at 12:40 am

    Given the clarified question, here’s a new solution.

    UPDATED

    “Slurp” the entire block of data (including the newline characters and all) into a single string, first.

    str = IO.read("report.rtf")
    

    Then use this regex:

    captures = str.scan(/(?<=^|[\r\n])([A-Z][^:]*):([^\r\n]*(?:[\r\n]+(?![A-Z].*:).*)*)/)
    

    See a live example here: http://rubular.com/r/8w3X6WGq4l.

    The answer, explained:

        (?<=                Lookbehind assertion.
            ^                   Start at the beginning of the string,
            |                   or,
            [\r\n]              a new line.
        )
        (                   Capture group 1, the "key".
            [A-Z][^:]*          Capital letter followed as many non-colon
                                characters as possible.
        )
        :                   The colon character.
    
        (                   Capture group 2, the "value".
            [^\r\n]*            All characters (i.e. non-newline characters) on the
                                same line belongs to the "value," so take them all.
    
            (?:             Non-capture group.
    
                [\r\n]+         Having already taken everything up to a newline
                                character, take the newline character(s) now.
    
                (?!             Negative lookahead assertion.
                    [^A-Z].*:       If this next line contains a capital letter,
                                    followed by a string of anything then a colon,
                                    then it is a new key/value pair, so we do not
                                    want to match this case.
                )
                .*              Providing this isn't the case though, take the line!
    
            )*              And keep taking lines as long as we don't find a
                            key/value pair.
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.