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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:06:21+00:00 2026-05-19T16:06:21+00:00

I would like to be able to parse strings like the following: 123456abcd9876az45678. The

  • 0

I would like to be able to parse strings like the following: “123456abcd9876az45678”. The BNF is like this:

number: ? definition of an int ?
word: letter { , letter }
expression: number { , word , number }

However the class java.util.scanner doesn’t allow me to do the following:

Scanner s = new Scanner("-123456abcd9876az45678");
System.out.println(s.nextInt());
while (s.hasNext("[a-z]+")) {
    System.out.println(s.next("[a-z]+"));
    System.out.println(s.nextInt());
}

Ideally, this should yield:

-123456
abcd
987
az
45678

I was really hoping that java.util.Scanner would help me, but it looks like I will have to create my own scanner. Is there anything already present in the Java API to help me?


The question miss too much information. And therefore all answers are valid to the question but not to my problem.

  • 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-19T16:06:21+00:00Added an answer on May 19, 2026 at 4:06 pm

    Unfortunately you cannot use no delimiters with the Scanner class AFAIK. If you wish to ignore delimiters, you’d need to use the methods that does so such as findInLine() or findWithinHorizon(). In your case, findWithinHorizion() would be appropriate.

    Scanner s = new Scanner("-123456abcd9876az45678");
    Pattern num = Pattern.compile("[+-]?\\d+");
    Pattern letters = Pattern.compile("[A-Za-z]+");
    System.out.println(s.findWithinHorizon(num, 0));
    String str;
    while ((str = s.findWithinHorizon(letters, 0)) != null) {
        System.out.println(str);
        System.out.println(s.findWithinHorizon(num, 0));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to jQuery and would like to parse an XML document. I'm able
I need to be able to parse strings like these: kev-+kvs+-one-+gdl+-greg-+kvs+-two-+gdl+-les-+kvs+-three -+gdl+-kev-+kvs+-one-+gdl+-greg-+kvs+-two-+gdl+-les-+kvs+-three kev-+kvs+-one-+gdl+-greg-+kvs+-two-+gdl+-les-+kvs+-three-+gdl+- and
I would like to be able to take a string such as the following
I have the following XML document which I would like to parse into a
I have nested JSON strings that i would like to parse out the appropriate
Would like to be able to set colors of headings and such, different font
I would like to be able to output the name of a variable, along
I would like to be able to print in the logs a message for
I would like to be able to show a personal message to abusers of
I would like to be able to create a variable that holds an instance

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.