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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:10:31+00:00 2026-06-14T00:10:31+00:00

I have strings of the form: abc 1 2 1 13 efgh 2 5

  • 0

I have strings of the form:

"abc" 1 2 1 13 
"efgh" 2 5 

Basically, a string in quotes followed by numbers separated by whitespace characters.
I need to extract the string and the numbers out of the line.

So for eg., for the first line, I’d want

  • abc to be stored in a String variable (i.e. without the quotations) and
  • an array of int to store [1,2,1,13].

I tried to create a pattern that’d do this, but I’m a little confused.

Pattern P = Pattern.compile("\A\".+\"(\s\d+)+");

Not sure how to proceed now. I realized that with this pattern I’d kinda be extracting the whole line out? Perhaps multiple patterns would help?

Pattern P1 = Pattern.compile("\A\".+\"");
Pattern P2 = Pattern.compile("(\s\d+)+");

Again, not very sure how to get the string and ints out of the line though. Any help is 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-06-14T00:10:33+00:00Added an answer on June 14, 2026 at 12:10 am

    I would rather just split the string on space, rather than building complex regex, and use it with Pattern and Matcher class.

    Something like this: –

    String str = "\"abc\" 1 2 1 13 ";
    String[] arrr = str.split("\\s");
    System.out.println(Arrays.toString(arrr));
    

    OUTPUT: –

    ["abc", 1, 2, 1, 13]
    

    Shows your intent much clearer, that what you want to do.

    Then, you can get the string and integer parts from your string array. You would need to do a Integer.parseInt() on integer elements.


    If your string may contain spaces in it, then in that case, you would need a Regex. Better one would be the one in @m.buettner's answer

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

Sidebar

Related Questions

i have strings in the form [abc].[some other string].[can.also.contain.periods].[our match] i now want to
I have strings of following form a = x + y or abc =
I have a string of the form foo-bar-1.23-4, and I need to split at
I have a situation where I need to concatenate several string to form an
I have a file path in String form. In Java, I need to determine
I have strings of the following form: 37, 42, 7. I need to transform
I have a bunch of strings of the form: AAA.BBB[0].CCC.DDD[5].EEE = 123. Some contain
I have an array of strings of the form: @source = ( something,something2,third ,something,something3
I seem to have a problem passing some strings on from one form to
I have an array of integers in string form: var arr = new string[]

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.