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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:05:22+00:00 2026-06-09T07:05:22+00:00

I have a data file in which each line represents a single record and

  • 0

I have a data file in which each line represents a single record and each record may contain a list of keywords, each preceded by a “+”.

foo1 foofoo foo foo foo +key1 +key2 +key3
foo2 foo foo foofoo foo 
foo3 foo foofoo foo +key1 key1 key1 +key2

There wil be between zero and a theoretically unlimited number of keywords.
Keywords will ALWAYS be preceded by a +.
Individual keywords MAY be a single word, or a phrase with spaces.
My strategy for identifying keywords:

I would like to read these records into an array, String keywords[]. I’m using lineBuffer to bring the data in, and here’s what I have so far.

// PSEUDOCODE
counter = [number of occurences of + in the line];
for(int i=0;i<=counter,i++) {
    Pattern p = [regex reresenting + to the next occurence of + -or- end of line];
    Match pattern;
    keyword[i] = Match.group(1) }

I may be over-thinking this, but does Java know to go to the next instance of my pattern in the same line? Looking at these few lines of code, it seems that my pattern matcher would read the line, find the first instance of a keyword and write it to the array i number of times. It would never GET to the second keyword.

Is there a better way to think about this? A better strategy for creating this array?

  • 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-09T07:05:23+00:00Added an answer on June 9, 2026 at 7:05 am

    If you know that there is no + in the keys, you could simply split the string:

    String[] ss = s.split(" \\+");
    

    And discard the first entry (the foo fooo…).

    EDIT

    Regarding the pattern / regex question, you could also do it that way:

    Pattern p = Pattern.compile(" \\+\\w+");
    Matcher m = p.matcher(s);
    while (m.find()) {
        String key = m.group().trim().replaceAll("\\+","");
        System.out.println(key);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file with 50k+- lines and each line contains data which
I have .zip file which contain csv data. I am reading .zip file using
I have a table which represents a line-by-line dump of the data read from
I have a data file, with each line holding one number. I am trying
I have a data file which is comprised of rows of data, newline separated.
I have a data file, which I need to read. I know to read
I have a file data.base which looks like: 1234 XXXX 4321 XXXX 9884 ZZZZ
I have a System.Data.DataTable which is populated by reading a CSV file which sets
I have a file which contains lines of data in the following format: a11
I have a text file which contains data seperated by '|'. I need to

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.