bash - check for string to be list of integers separated by + signs in python -


I want to see that the mivar be divided by more than one integer + . Should it be re.search () enough?

  myvar = "1 + 2 + 3" if (re-search (r "^ [0- 9] + (\ + [0-9] +) * $", miver) : "Print" should be an integer integer (% s) "% myvar sys.exit (1)   

Then I realized that it would still work for the wrong cases such as:

  myvar = "1 + 2 + 3-4"    

Use a regex free alternative partition:

  myvars = ["+1", "1 + 2 + 2", "1 + 5", "1 + 2 + 3 "] for myvars in hevor: nums = myvar.split ('+') for num: num: try: int (num): print" error ", myover   

< em> returns:

  error +1 error 1++ 2    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -