http://www.perlmonks.org?node_id=1214539


in reply to Re^2: check if string is valid with special cases
in thread check if string is valid with special cases

the substring can conatin commas in it

Sorry, this doesn't make sense to me. If the input string is "1,2,3,4,5,6,7", then does $a get "1,2", or does $b get "2,3", and so on...

Or is this CSV, as swl correctly pointed out? Then you should use Text::CSV.

If not, then as I said, please provide lots of examples of valid input with the expected output, as well as lots of examples of invalid input.

Replies are listed 'Best First'.
Re^6: check if string is valid with special cases
by ovedpo15 (Pilgrim) on May 15, 2018 at 11:21 UTC
    "a ,b,c,d,e" is okay (space with substring) but one space or more (without any symbols) isn't valid. For example: "a, ,c,d,e" or "a,b,c, d,e" are not valid.
Re^4: check if string is valid with special cases
by ovedpo15 (Pilgrim) on May 15, 2018 at 11:09 UTC
    Ok I understand, forget about commas in the substrings.
    your regex is good and its what I need except it doesn't handle an empty space case: "a,b,c, d,e" (bad case).
    how can I add it to the regex?

      Again, more examples please. Only literal spaces? I am guessing you mean one or more spaces? What about other whitespace? Is " x ,..." valid? Is " x y ,..."? What is the expected output for those cases? And so on.