Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: check if string is valid with special cases

by ovedpo15 (Acolyte)
on May 15, 2018 at 10:30 UTC ( #1214537=note: print w/replies, xml ) Need Help??


in reply to Re: check if string is valid with special cases (updated)
in thread check if string is valid with special cases

Im sorry, I meant that the substring can conatin commas in it. nevertheless, is it possible to include a case of space (bad case - "1,2,3, ,4,5") for the regex you wrote? I think its the regex I need.
  • Comment on Re^2: check if string is valid with special cases

Replies are listed 'Best First'.
Re^3: check if string is valid with special cases
by haukex (Abbot) on May 15, 2018 at 10:58 UTC
    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.

      "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.
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1214537]
help
Chatterbox?
and cookies bake in the oven...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-05-25 02:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?