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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:03:48+00:00 2026-05-21T13:03:48+00:00

I need to build a regex that match words with these patterns: Letters and

  • 0

I need to build a regex that match words with these patterns:

Letters and numbers:

A35, 35A, B503X, 1ABC5

Letters and numbers separated by “-“, “/”, “\”:

AB-10, 10-AB, A10-BA, BA-A10, etc…

I wrote this regex for it:

\b[A-Za-z]+(?=[(?<!\-|\\|\/)\d]+)[(?<!\-|\\|\/)\w]+\b|\b[0-9]+(?=[(?<!\-|\\|\/)A-Za-z]+)[(?<!\-|\\|\/)\w]+\b

It works partially, but it’s match only letters or only numbers separated by symbols.
Example:

10-10, open-office, etc.

And I don’t wanna this matches.

I guess that my regex is very repetitive and somewhat ugly.
But it’s what I have for now.

Could anyone help me?

I’m using java/groovy.

Thanks in advance.

  • 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-21T13:03:48+00:00Added an answer on May 21, 2026 at 1:03 pm

    Interesting challenge. Here is a java program with a regex that picks out the types of “words” you are after:

    import java.util.regex.*;
    public class TEST {
        public static void main(String[] args) {
            String s = "A35, 35A, B503X, 1ABC5 " +
                "AB-10, 10-AB, A10-BA, BA-A10, etc... " +
                "10-10, open-office, etc.";
            Pattern regex = Pattern.compile(
                "# Match special word having one letter and one digit (min).\n" +
                "\\b                       # Match first word having\n" +
                "(?=[-/\\\\A-Za-z]*[0-9])  # at least one number and\n" +
                "(?=[-/\\\\0-9]*[A-Za-z])  # at least one letter.\n" +
                "[A-Za-z0-9]+              # Match first part of word.\n" +
                "(?:                       # Optional extra word parts\n" +
                "  [-/\\\\]                # separated by -, / or //\n" +
                "  [A-Za-z0-9]+            # Match extra word part.\n" +
                ")*                        # Zero or more extra word parts.\n" +
                "\\b                       # Start and end on a word boundary", 
                Pattern.COMMENTS);
            Matcher regexMatcher = regex.matcher(s);
            while (regexMatcher.find()) {
                System.out.print(regexMatcher.group() + ", ");
            } 
        }
    }
    

    Here is the correct output:

    A35, 35A, B503X, 1ABC5, AB-10, 10-AB, A10-BA, BA-A10,

    Note that the only complex regexes which are “ugly”, are those that are not properly formatted and commented!

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

Sidebar

Related Questions

I need to build a regex (in PHP) that match if a string has
I need help to build a regex that can remove EVEN lines in a
I need to build a regex. the string i want to match always starts
I need to build something that starts serving a H.264 encoded video to a
I need to dynamically build a Regex to catch the given keywords, like string
I'm trying build a regex that will replace any characters not of the format:
I have a regex I need to match against a path like so: C:\Documents
Hi I need an ICU regex that I think it is pretty basic but
I need to build ONE regular expression that can detect ALL the following strings
I need to build a Regex (.NET syntax) to determine if a string ends

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.