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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:46:23+00:00 2026-05-25T15:46:23+00:00

Im going to start by posting what the date in the text file looks

  • 0

Im going to start by posting what the date in the text file looks like, this is just 4 lines of it, the actually file is a couple hundred lines long.

Friday, September 9 2011
-STV 101——–05:00 – 23:59 SSB 4185 Report Printed on 9/08/2011 at 2:37

0-AH 104——–07:00 – 23:00 AH GYM Report Printed on 9/08/2011 at 2:37

-BG 105——–07:00 – 23:00 SH GREAT HALL Report Printed on 9/08/2011 at 2:37

What I want to do with this text file is ignore the first line with the date on it, and then ignore the ‘-‘ on the next line but read in the “STV 101”, “5:00” and “23:59” save them to variables and then ignore all other characters on that line and then so on for each line after that.

Here is how I am currently reading the lines entirely. And then I just call this function once the user has put the path in the scheduleTxt JTextfield. It can read and print each line out fine.

public void readFile () throws IOException
{
    try
    {
        FileInputStream fstream = new FileInputStream(scheduleTxt.getText());
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;

        while ((strLine = br.readLine()) != null)   
        {
            System.out.println (strLine);
        }
        in.close();
    }
    catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
}

UPDATE: it turns out I also need to strip Friday out of the top line and put it in a variable as well
Thanks! Beef.

  • 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-25T15:46:24+00:00Added an answer on May 25, 2026 at 3:46 pm

    Did not test it thoroughly, but this regular expression would capture the info you need in groups 2, 5 and 7: (Assuming you’re only interested in “AH 104” in the example of “0-AH 104—-“)
    ^(\S)*-(([^-])*)(-)+((\S)+)\s-\s((\S)+)\s(.)*

        String regex = "^(\\S)*-(([^-])*)(-)+((\\S)+)\\s-\\s((\\S)+)\\s(.)*";
        Pattern pattern = Pattern.compile(regex);
        while ((strLine = br.readLine()) != null){
            Matcher matcher = pattern.matcher(strLine);
            boolean matchFound = matcher.find();
            if (matchFound){
                String s1 = matcher.group(2);
                String s2 = matcher.group(5);
                String s3 = matcher.group(7);
                System.out.println (s1 + " " + s2 + " " + s3);
            }
    
        }
    

    The expression could be tuned with non-capturing groups in order to capture only the information you want.

    Explanation of the regexp’s elements:

    1. ^(\S)*- Matches group of non-whitespace characters ended by -. Note: Could have been ^(.)*- instead, would not work if there are whitespaces before the first -.
    2. (([^-])*) Matches group of every character except -.
    3. (-)+ Matches group of one or more -.
    4. ((\S)+) Matches group of one or more non-white-space characters. This is captured in group 5.
    5. \s-\s Matches group of white-space followed by - followed by whitespace.
    6. ‘((\S)+)’ Same as 4. This is captured in group 7.
    7. \s(.)* Matches white-space followed by anything, which will be skipped.

    More info on regular expression can be found on this tutorial.
    There are also several useful cheatsheets around. When designing/debugging an expression, a regexp testing tool can prove quite useful, too.

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

Sidebar

Related Questions

We are going to start a long lasting project using C++ as the programming
I'm going to start working on project developed in ASP.NET. In this project I
I'm going to start on a long (~1-year) programming project in Python. I want
i am going to start a chess like board game. and for that i
Just going to start making a web application and was wondering which was better,
I'm going to start taking an excel file for a bulk member upload in
i am going to start a speech to text app in iphone and i
I am going to start on a new project for my school. I have
I am going to start working on a website that has already been built
I am going to start a project of my own, which will be ASP.NET

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.