jeudi 20 septembre 2018

C++ - std::regex for input validation instead of conditional logic

I currently have the following regular expression:

([1-6](\\s|,)*){1,6}

This will accept : a number from 1 to 6, followed by any number of spaces or commas, anywhere from 1 - 6 times.

You can find some examples below :

  • 1,4 , 2,
  • 3, 3, 3, 3

This regular expression alone does not disqualify all invalid inputs, as integers should not be allowed to reoccur. I know that this is possible to achieve through regex syntax alone, however I am not able to make an educated decision on whether or not I want to just use conditional statements instead. I am curious about how the two techniques compare in the following areas:

  1. compile time / method overhead
  2. run time / memory management efficiency
  3. readability (your personal opinion please)
  4. ease of use (your personal opinion please)

Aucun commentaire:

Enregistrer un commentaire