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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:03:55+00:00 2026-05-15T03:03:55+00:00

Looking to parse the following text file: Sample text file: <2008-10-07>text entered by user<Ted

  • 0

Looking to parse the following text file:
Sample text file:

<2008-10-07>text entered by user<Ted Parlor><2008-11-26>additional text entered by user<Ted Parlor>

I would like to parse the above text so that I can have three variables:

v1 = 2008-10-07
v2 = text entered by user
v3 = Ted Parlor
v1 = 2008-11-26
v2 = additional text entered by user
v3 = Ted Parlor

I attempted to use scanner and useDelimiter, however, I’m having issue on how to set this up to have the results as stated above. Here’s my first attempt:

import java.io.*;
import java.util.Scanner;

public class ScanNotes {
    public static void main(String[] args) throws IOException {
        Scanner s = null;
        try {
            //String regex = "(?<=\\<)([^\\>>*)(?=\\>)";
            s = new Scanner(new BufferedReader(new FileReader("cur_notes.txt")));
            s.useDelimiter("[<]+");

            while (s.hasNext()) {
                String v1 = s.next();
                String v2= s.next();
                System.out.println("v1= " + v1 + " v2=" + v2);
            }
        } finally {
            if (s != null) {
                s.close();
            }
        }
    }
}

The results is as follows:

v1= 2008-10-07>text entered by user v2=Ted Parlor> 

What I desire is:

v1= 2008-10-07 v2=text entered by user v3=Ted Parlor
v1= 2008-11-26 v2=additional text entered by user v3=Ted Parlor

Any help that would allow me to extract all three strings separately would be greatly appreciated.

  • 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-15T03:03:56+00:00Added an answer on May 15, 2026 at 3:03 am

    You can use \s*[<>]\s* as delimiter. That is, any of < or >, with any preceding and following whitespaces.

    For this to work, there must not be any < or > in the input other than the ones used to mark the date and user fields in the input (i.e. no I <3 U!! in the message).

    This delimiter allows empty string parts in an entry, but it also leaves empty string tokens between any two entries, so they must be discarded manually.

    import java.util.Scanner;
    
    public class UseDelim {
        public static void main(String[] args) {
            String content = " <2008-10-07>text entered by user <Ted Parlor>"
            + "   <2008-11-26>  additional text entered by user <Ted Parlor>"
            + "   <2008-11-28><Parlor Ted>  ";
            Scanner sc = new Scanner(content).useDelimiter("\\s*[<>]\\s*");
            while (sc.hasNext()) {
                System.out.printf("[%s|%s|%s]%n",
                    sc.next(), sc.next(), sc.next());
    
                // if there's a next entry, discard the empty string token
                if (sc.hasNext()) sc.next();
            }
        }
    }
    

    This prints:

    [2008-10-07|text entered by user|Ted Parlor]
    [2008-11-26|additional text entered by user|Ted Parlor]
    [2008-11-28||Parlor Ted]
    

    See also

    • regular-expressions.info/Character classes
    • regular-expressions.info/Repetition
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rather large text file (~4m lines) I'd like to parse and
I'm looking for the Javascript to parse the following HTML: <p>random text random text
I'm looking at XML Pull parsing approach to parse the following document: <layout> <button
I am looking to parse and modify a project file of type .dbproj .
I have the following String that I need to parse. I am looking for
I'm looking around for a RegEx that can help me parse an nquad file.
I have the following basic code to read a text file from a StreamReader:
I am trying to parse a large XML file using JavaScript. Looking online, it
I am trying to parse a table in the form of a text file
I have the following text that I am trying to parse: user1@emailaddy1.com <user1@emailaddy1.com>, Jane

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.