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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:42:21+00:00 2026-05-31T19:42:21+00:00

I need a regex that allows numbers and optional commas, but the entire length

  • 0

I need a regex that allows numbers and optional commas, but the entire length cannot be greater than 6.

^[0-9]+([,]*[0-9]+)*$ allows numbers and optional commas.

^([0-9]+([,]*[0-9]+)*){0,6}$ does not limit the total length to 6.

  • 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-31T19:42:22+00:00Added an answer on May 31, 2026 at 7:42 pm

    If your regex engine supports lookahead assertions — most do — then you can write:

    ^(?=[0-9,]{1,6}$)[0-9]+(,[0-9]+)*$
    

    The (?=[0-9,]{1,6}$) part is a “positive lookahead assertion”, and means “looking forward from this point in the string, I see [0-9,]{1,6}$“. So, in essence, the above regex is a combination of these two:

    ^[0-9,]{1,6}$
    ^[0-9]+(,[0-9]+)*$
    

    and enforces them both.

    (That said, it’s likely to be clearer if you simply enforce the length restriction as a separate step, rather than incorporating the above into a single regex.)

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

Sidebar

Related Questions

I need a regex that will match blahfooblah but not blahfoobarblah I want it
I need a regex that matches all strings ending in .cs, but if they
I need help writing a regex for a phone number pattern that allows the
I have a regex that right now only allows lowercase letters, I need one
I need to find a reg ex that only allows alphanumeric. So far, everyone
I need a Regex that will match a java method declaration. I have come
I need a regex that also matches Chinese, Greek, Russian, ... letters. What I
I need a regex that matches the following (the brackets indicate I want to
I need a regex that will give me the following results from each example
Given a file path such as: \\server\folder_A\folder_B\etc\more.mov I need a regex that'll give me

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.