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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:50:00+00:00 2026-05-24T09:50:00+00:00

I need to match a string (any character or symbol other than space) with

  • 0

I need to match a string (any character or symbol other than space) with length of 10 and at least a number (but uncertain location) in it. What’s the easiest way to do it? Thx! (preferably in Perl Regex but really any regex would shed light on it.)

Some sample strings that meet the requirement:

ABCD1EFGH2
AGD-D.D8HD
1414151502
[TT]88daJh

Some samples that do NOT meet the requirement:

ABCDEFGHIJ        # no digit
EGEGE_(**/        # no digit
asdgja8G          # too short
@#21-GDKJGDE      # too long

Thx!

UPDATE: To be clear, this is a search. The input string has thousands of characters long. I need to match out all the 10-character “words” that have a digit in them. You can think of a string that contains all above 8 words separated by space(s) and tab(s). Would like a search that picks out the first 4 only. Thx!

UPDATE of UPDATE: Apologize for not being clear again (wanted to simplify the case, but failed to exclude alternative interpretations). The usage for this regex search would be part of a longer match. Eg. A 10-char word with at least a digit followed by a 4-char word, etc… So splitting the long string as the first step wouldn’t quite work.

  • 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-24T09:50:01+00:00Added an answer on May 24, 2026 at 9:50 am

    That was a very important clarification; finding the kind of strings you describe within a larger string is a very different task from matching standalone strings, and much more complicated. I think the easiest way to do it is with lookarounds:

    /(?<!\S)(?=\S{10}(?!\S))\S*\d\S*/
    

    (?<!\S) matches a position that is not preceded by a non-whitespace character.

    (?=\S{10}(?!\S)) further asserts that the position is followed by exactly 10 non-whitespace characters.

    Once the lookarounds are satisfied, \S*\d\S* goes ahead and consumes the string, assuming at least one of the characters is a digit.

    This will work in Perl and most of the Perl-derived flavors, like Python, Java, and .NET, but not in JavaScript, which doesn’t support lookbehinds.


    EDIT: Here’s an example showing how to iterate through all matches in Perl:

    while ($subject =~ m/(?<!\S)(?=\S{10}(?!\S))\S*\d\S*/g) {
        print("$&\n");
    }
    

    …and here’s a live demo (which also includes the optimization discussed in the comments).

    In JavaScript I’d use a slightly different regex:

    var regex = /(?:\s|^)(?=\S{10}(?!\S))([^\d\s]*\d\S*)/g;
    var match = regex.exec(subject);
    while (match != null) {
        print(match[1]);
        match = regex.exec(subject);
    }
    

    Replacing the lookbehind with (?:\s|^) means I’m consuming the leading whitespace character now. To extract the word alone, I capture it with () and retrieve it with match[1]. demo

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

Sidebar

Related Questions

I need to match any kind of string which has at least a .
I need to find a regex that will match any string, at least 6
I need a regular expression able to match everything but a string starting with
I need to match a string that is prefixed with an acceptable length for
I need a regular expression for JavaScript that will match any string that does
I need to match a string holiding html using a regex to pull out
I need a Perl regular expression to match a string. I'm assuming only double-quoted
i need a regexp to match only single / in a string in PHP.
From a string, I need to pull out groups that match a given pattern.
I need a regular expression that matches a 15 character string as follows: Characters

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.