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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:56:38+00:00 2026-05-13T07:56:38+00:00

I have multiple strings that are in the following format: 12/18/2009 02:08:26 Admitted Doe,

  • 0

I have multiple strings that are in the following format:
12/18/2009 02:08:26 Admitted Doe, John (Card #111) at South Lobby [In]

From these string I need to get out the date, time, first and last name of the person, and the card number. The word admitted can be omitted and anything following the final digit of the card number can be ignored.
I have a feeling I want to use StringTokenizer for this, but I’m not positive.
Any 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-13T07:56:39+00:00Added an answer on May 13, 2026 at 7:56 am

    Your record format is simple enough that I’d just use String’s split method to get the date and time. As pointed out in the comments, having names that can contain spaces complicates things just enough that splitting the record by spaces won’t work for every field. I used a regular expression to grab the other three pieces of information.

    public static void main(String[] args) {
        String record1 = "12/18/2009 02:08:26 Admitted Doe, John (Card #111) at South Lobby [In]";
        String record2 = "12/18/2009 02:08:26 Admitted Van Halen, Eddie (Card #222) at South Lobby [In]";
        String record3 = "12/18/2009 02:08:26 Admitted Thoreau, Henry David (Card #333) at South Lobby [In]";
    
        summary(record1);
        summary(record2);
        summary(record3);
    }
    
    public static void summary(String record) {
        String[] tokens = record.split(" ");
    
        String date = tokens[0];
        String time = tokens[1];
    
        String regEx = "Admitted (.*), (.*) \\(Card #(.*)\\)";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(record);
        matcher.find();
    
        String lastName = matcher.group(1);
        String firstName = matcher.group(2);
        String cardNumber = matcher.group(3);
    
        System.out.println("\nDate: " + date);
        System.out.println("Time: " + time);
        System.out.println("First Name: " + firstName);
        System.out.println("Last Name: " + lastName);
        System.out.println("Card Number: " + cardNumber);
    }
    

    The regular expression "Admitted (.*), (.*) \\(Card #(.*)\\)" uses grouping parentheses to store the information you’re trying to extract. The parentheses that exist in your record must be escaped.

    Running the code above gives me the following output:

    Date: 12/18/2009
    Time: 02:08:26
    First Name: John
    Last Name: Doe
    Card Number: 111
    
    Date: 12/18/2009
    Time: 02:08:26
    First Name: Eddie
    Last Name: Van Halen
    Card Number: 222
    
    Date: 12/18/2009
    Time: 02:08:26
    First Name: Henry David
    Last Name: Thoreau
    Card Number: 333
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a row of strings that are in the following format: 'Order was
I have multiple different keys generated in the following format: 71 1 2, 69
I have a text files that contains multiple lines, each line has the following
I have a hashmap that contains multiple string arrays. I am trying to output
The question is simple. I have a string that contains multiple elements which are
I have a long string of comments that I'd like to split into multiple
i have multiple strings containing a link like: <A HREF=http://www.testings2>testings2</A> <A HREF=http://www.blabla>blabla</A> <A HREF=http://www.gowick>gowick</A>
i have a single textbox named Keywords. User can enter multiple strings for search.
I have a program that is creating multiple files. There is a function for
If I have to save many strings that are related and that may be

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.