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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:17:28+00:00 2026-05-22T22:17:28+00:00

I have a CSV string that I am trying to validate via regex to

  • 0

I have a CSV string that I am trying to validate via regex to ensure it only has N items. I’ve tried the following pattern (which look for 2 items):

/([^,]+){2}/

But it doesn’t seem to work, I am guessing because the inner pattern isn’t greedy enough.

Any ideas? Ideally it should work with both the PHP and Javscript regex engines.

Update:

For technical reasons I really want to do this via regex rather than another solution. The CSV is not quoted and the values will not contain commas, so that isn’t a problem.

/([^,]*[,]{1}[^,]*){1}/

Is where I am at now, which sort of works but is still a bit ugly, and has issues matching one item.

CSV looks like:

apples,bananas,pears,oranges,grapefruit
  • 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-22T22:17:29+00:00Added an answer on May 22, 2026 at 10:17 pm

    Got it.

    /^([^,]+([,]{1}|$)){1}$/
    

    Set the last {N} to the quantity of results or range {1,3} to check.

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

Sidebar

Related Questions

I am trying to write a regex that will allow me to parse CSV
I have a list of string that I am writing out to a CSV
If i have a CSV file that is in the following format fd!,sdf,dsfds,dsfd fd!,asdf,dsfds,dsfd
I am have a few issues with trying to locate a number that has
I'm trying to read a CSV with R from a URL that has auth
I have a big string (let's call it a CSV file, though it isn't
I have a .csv file that is frequently updated (about 20 to 30 times
I have a CSV file that holds about 200,000 - 300,000 records. Most of
I have a CSV data file with rows that may have lots of columns
I have a CSV of file of data that I can load in R

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.