Search code examples
phpregexposix-ere

Help with a regular expression


I'd like to write a regular expression that checks that a line is:

  • Delimited (by a comma, for example)
  • Has at least n # of delimited items (say 10, for example)

The items in the delimited list need not be alphanumeric. Some will have special characters. Also, some items may be absent, so there is no assurance that there will be something between delimiters.

I'm a newb to regexp so if your answer involves anything extra clever/advanced please explain

Thanks much


Solution

  • /^[^,]*(?:,[^,]*){9,}$/