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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T17:18:56+00:00 2026-06-02T17:18:56+00:00

I admittedly am not a Regular Expression expert, but would like to validate an

  • 0

I admittedly am not a Regular Expression expert, but would like to validate an input string and writing if/else statements for various validations just isn’t the way to do this. I’m using Java.

The input will be in the form a colon (:) separated tuple of three values. The first value will be an integer (potentially a long in terms of size/length), with the other two values being either numberic or a string.

For example, the following values would be valid:

  • 1:x:456
  • 2:2:3
  • 3:abc:123

..and these would not:

  • x:1:2
  • 1::2
  • 1:3::x
  • 1:2
  • fyz::2:1
  • 1:3::3

Is there a relatively easy way to validate this input using a regular expression?

  • 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-02T17:18:57+00:00Added an answer on June 2, 2026 at 5:18 pm

    Matching Numbers:(letters OR numbers):(letters OR numbers)

    If you want it such that it has to be numbers or letters only for 2nd and 3rd part, you can use this pattern:

    String pattern = "^\\d+(:([A-Za-z]+|\\d+)){2}$";
    

    Basically it will look for a sequence of numbers (\\d+), followed by a twice-repeated sequence of characters:

    • starting with a a :, followed by
      • a sequence of letters (English), that is [A-Za-z], OR
      • a sequence of numbers

    The ^ and $ characters are anchors, meaning “beginning-of-string” and “end-of-string”

    Example:

    public class RegexTest {
        public static void Main(String[] args) {
            String pattern = "^\\d+(:([A-Za-z]+|\\d+)){2}$";
            String example = "333:abc:123456";
            if (example.matches(pattern)) {
               System.out.println("Matches");
            }   
        }
    }
    

    Matching Numbers:(both letters and numbers:(both letters and numbers)

    For this, you can use this pattern:

    String pattern = "^\\d+(:[A-Za-z0-9]+){2}$";
    

    Which will match:

    • A series of digits, followed by
    • A colon, followed by any combination of letters or numbers
      • repeat this sequence twice

       public class RegexTest {
            public static void Main(String[] args) {
                String pattern = "^\\d+(:[A-Za-z0-9]+){2}$";
                String example = "333:a3b4c:12adf3456";
                if (example.matches(pattern)) {
                   System.out.println("Matches");
                }   
            }
        }
    

    This example will match.

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

Sidebar

Related Questions

Admittedly not a programming question, but I don't really know where else to ask
I'm admittedly not the most experienced with C++, but am surprised to be having
I am admittedly not as skilled in PHP as I would hope to be.
In my admittedly young career I've found myself writing code to support quirky business
(The title is admittedly not that great. Please forgive my English, this is the
Admittedly a misleading title, but I didn't know how to put it better. So
Admittedly, this is a strange problem for me to have, but here is what
I'm parsing some text (admittedly HTML, but it's small stuff, and RegEx (should) do
I admittedly am not very proficient with Javascript (and subsequently AJAX). I have a
I'm looking at options for providing Faceted Search functionality, admittedly not a specialty of

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.