Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Using regular expression in perl

View previous topic View next topic Go down 
AuthorMessage
TAXXX
Member
Member
avatar

Posts : 19
Join date : 2011-03-09

Using regular expression in perl  Empty
PostSubject: Using regular expression in perl    Using regular expression in perl  EmptyFri Mar 25, 2011 8:52 pm

Hello Guys,

Sorry, I am not sure if this thread belongs here.
I am new to perl and writing a regex for identifying if the user input lies in the set [0,100), i.e. the number must lie between 0-100, 0 included. It can be of form 0.000001, .00001, 90, 90.999153263, .12 etc
Following is the regex I wrote: $input =~ /\d\d?\.\d+|(\d\d?|\.\d+)/, but I am not gettinh the result. Can someone help me in this?
Thanks a bunch
Back to top Go down
Corverta
Member
Member
avatar

Posts : 20
Join date : 2011-03-09

Using regular expression in perl  Empty
PostSubject: Re: Using regular expression in perl    Using regular expression in perl  EmptyFri Mar 25, 2011 8:54 pm

TAXXX wrote:
Hello Guys,

Sorry, I am not sure if this thread belongs here.
I am new to perl and writing a regex for identifying if the user input lies in the set [0,100), i.e. the number must lie between 0-100, 0 included. It can be of form 0.000001, .00001, 90, 90.999153263, .12 etc
Following is the regex I wrote: $input =~ /\d\d?\.\d+|(\d\d?|\.\d+)/, but I am not gettinh the result. Can someone help me in this?
Thanks a bunch

Try this
Code:

/^(\d{0,2}\.\d*)$/
Back to top Go down
TAXXX
Member
Member
avatar

Posts : 19
Join date : 2011-03-09

Using regular expression in perl  Empty
PostSubject: Re: Using regular expression in perl    Using regular expression in perl  EmptyFri Mar 25, 2011 8:54 pm

Thanks for the prompt reply.
I have a confusion, in the code /^(\d{0,2}\.\d*)$/ if I am correct, it will search for exact one decimal(.) in such scenario, an integer given as input 10, 25 which does not contain decimal will be marked as invalid.
Back to top Go down
Corverta
Member
Member
avatar

Posts : 20
Join date : 2011-03-09

Using regular expression in perl  Empty
PostSubject: Re: Using regular expression in perl    Using regular expression in perl  EmptyFri Mar 25, 2011 8:56 pm

TAXXX wrote:
Thanks for the prompt reply.
I have a confusion, in the code /^(\d{0,2}\.\d*)$/ if I am correct, it will search for exact one decimal(.) in such scenario, an integer given as input 10, 25 which does not contain decimal will be marked as invalid.
yes you are right. if you want to add integers and exclude dot try this way:

Code:

/^(\d{0,2}(\.\d*)?)$/

Good luck
Back to top Go down
Sponsored content




Using regular expression in perl  Empty
PostSubject: Re: Using regular expression in perl    Using regular expression in perl  Empty

Back to top Go down
 

Using regular expression in perl

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Use of cookies on a perl CGI

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Using regular expression in perl  Edit-trash Useless :: Trash-