Perl regex for -1 or any positive integer (but not 0) -


i need match integer either -1, or positive integer (but not 0). should possible using regex, i've found difficult grasp.

i'd grateful if couldtell me how match it, , provide explanation @ same time, learn something.

thanks.

don't try cleaver. this:

if (( $value == int( $value ) , $value > 0 ) or $value == -1 ) {   .... } 

and avoid regular expressions can prone errors -- when overly complicated.

this makes absolutely clear want. want integer that's greater 0, or -1. plus, wouldn't surprise me if more efficient parsing regular expression.

let's @ solution:

if ( $value =~ /-1|[1-9][0-9]*/ ) {     .... } 

this match -1 , match 42, not 0. however, match -1344 , 1vvv. nor, match ٢٤ integer 42 in arabic.

most of programming (or poor sucker comes after you) maintaining program: adding features, tracking down bugs.

don't try cleaver. because takes fewer lines type doesn't mean more efficient or better.


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -