java - Formulating a regex with a single dot -


i trying formulate regex following scenario :

the string match : mname87.com

so, string may consist of number of alpha numeric characters , can contain single dot anywhere in string .

i formulated regex : [a-za-z0-9.], matches multiple dots(.)

what doing wrong here ?

the regex provided matches single character in whole string you're trying validate. there few things take care of in scenario

  • you want match on whole string, regex must start ^ (beginning of string) , end $ (end of string).
  • then want accept number of alpha-numeric characters, done [a-za-z0-9]+, here + means 1 or more characters.
  • then match point: \. (you must escape here)
  • finally accept more characters again.

all regex be:

^[a-za-z0-9]+\.[a-za-z0-9]+$ 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -