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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:31:51+00:00 2026-06-18T07:31:51+00:00

I am receiving data in this forma, each of these three lines is it’s

  • 0

I am receiving data in this forma, each of these three lines is it’s own string:

   0 -rw-------    1       167 Tue Nov 13 10:39:28 2012 .bash_history
   0 -rw-r--r--    1        40 Wed Nov 28 12:18:03 2012 aaa.txt
22290 -rw-r--r--    1  22824944 Tue Jan 15 15:05:58 2013 a.bin

I tried using this regex to split it into tokens delimited by white space.

String[] tokens = newParts[i].split("\\s{1,}");

However this is always creating the first token as an empty string for the first two lines, and correctly sets 22290 as the first token for the third line. Why is this? All the rest of the tokens are as I want. Just not the first one of the first two lines, why?

  • 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-18T07:31:52+00:00Added an answer on June 18, 2026 at 7:31 am

    To quote the Pattern.split documentation:

    The array returned by this method contains each substring of the input sequence that is terminated by another subsequence that matches this pattern or is terminated by the end of the input sequence.

    So if your string starts with the separator, your first element will be an empty string. The same way, if your string ends with the separator, your last element will be an empty string.

    Edit: Actually split(string) calls split(string, 0), which explicitly discards trailing empty elements. But it doesn’t do anything about empty starting elements.

    It should work as you expect if you call trim() on the input first.

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

Sidebar

Related Questions

I have one thread that is receiving data over a socket like this: while
Why am I receiving this Rake error: $ rake --version /Volumes/Data/sampablokuper/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not
I have an application which is receiving data for thousands (say 50,000) subjects. Each
I am receiving JSON data to my server with dates represented like this: {
I'm receiving data packets in XML format, each with a specific documentRoot tag, and
I am receiving data representing a time slot from a service as a string
I am working on a small project that is receiving XML data in string
I am sending and receiving data using fsockopen and fwrite. My application receives the
I have strange problem with receiving data from socket. On client im using air
I am sending HTTP GET request and receiving data here: ssize_t numBytes = recvfrom(sock,

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.