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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:51:57+00:00 2026-05-25T00:51:57+00:00

I have an extremely long string that I want to parse for a numeric

  • 0

I have an extremely long string that I want to parse for a numeric value that occurs after the substring “ISBN”. However, this grouping of 13 digits can be arranged differently via the “-” character. Examples: (these are all valid ISBNs) 123-456-789-123-4, OR 1-2-3-4-5-67891234, OR 12-34-56-78-91-23-4. Essentially, I want to use a regex pattern matcher on the potential ISBN to see if there is a valid 13 digit ISBN. How do I ‘ignore’ the “-” character so I can just regex for a \d{13} pattern? My function:

public String parseISBN (String sourceCode) {
  int location = sourceCode.indexOf("ISBN") + 5;
  String ISBN = sourceCode.substring(location); //substring after "ISBN" occurs
  int i = 0;
  while ( ISBN.charAt(i) != ' ' )
    i++;
  ISBN = ISBN.substring(0, i); //should contain potential ISBN value
  Pattern pattern = Pattern.compile("\\d{13}"); //this clearly will find 13 consecutive numbers, but I need it to ignore the "-" character
  Matcher matcher = pattern.matcher(ISBN); 
  if (matcher.find()) return ISBN;
  else return null;
}
  • 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-25T00:51:58+00:00Added an answer on May 25, 2026 at 12:51 am
    • Alternative 1:

      pattern.matcher(ISBN.replace("-", ""))
      
    • Alternative 2: Something like

      Pattern.compile("(\\d-?){13}")
      

    Demo of second alternative:

    String ISBN = "ISBN: 123-456-789-112-3, ISBN: 1234567891123";
    
    Pattern pattern = Pattern.compile("(\\d-?){13}");
    Matcher matcher = pattern.matcher(ISBN);
    
    while (matcher.find())
        System.out.println(matcher.group());
    

    Output:

    123-456-789-112-3
    1234567891123
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm extremely new to JS and have this code that I'm trying to tweak.
We have a client who desires some extremely long pages. Say 4000px plus. They
I have some extremely weird behavior that seems to result in silent exceptions. How
I have a collection of PHP scripts that are extremely CPU intensive, juggling millions
I have a small db app that stores URL's of all lengths, some extremely
(See this question in ServerFault ) I have a Java client that uses Socket
If I have an extremely long floating point number in Ruby such as: x
I had this problem Cucumber scenarios for extremely long work flow And now I've
So I have this extremely memory-intensive Java application I'm building, which builds a tree
This is getting extremely irritating. Right now I have a winforms application, and things

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.