• Post Reply Bookmark Topic Watch Topic
  • New Topic

regular expression for strings  RSS feed

 
manepalli rajesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to write the following conditions with regular expressions.

1. Use 6 to 32 characters, no spaces

2. Use 4 to 32 characters and start with a letter.
You may use letters, numbers, underscores, and one dot (.).

please somebody help me


 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
manepalli rajesh wrote:

1. Use 6 to 32 characters, no spaces

2. Use 4 to 32 characters and start with a letter.
You may use letters, numbers, underscores, and one dot (.).


I tell you answare to the 1st question. the answare is



for 2nd question try yourself
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for 2nd question try yourself


Yeah, but you should really understand how regex works first. The first question was very basic -- and if you had a problem with that.... Again, it would probably be better to review regexes first.

Henry
 
manepalli rajesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi henry please help me
1. here the password must not contain whitespaces right? but when i am giving white spaces it is validating.


2.my userName should use letters, numbers, underscores, and one dot (.)
i wrote pattern like following is it correct?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:The first question was very basic -- and if you had a problem with that.... Again, it would probably be better to review regexes first.


I cant understand that where i am wrong?. Can you please explain me?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:
I cant understand that where i am wrong?. Can you please explain me?


Sorry. I was talking to the original poster. In that skipping the first case is not a good idea -- as you can't do the second case without knowing the first case.

I was not commenting on whether your answer was correct or not.

Henry
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manepalli,
I think the best way to write a complex regular expression is to write smaller ones. Can you figure out how to write a regular expression to match:
1) a single letter
2) any number of letters, numbers and underscores
3) At most one dot
4) A 4-32 character string

Once you know how to do all of the above, you can start figuring out how to merge them.

Seetharaman: We like to help people figure out how to solve problems and reason through them. After all - you won't be there when Manepalli is on the job. Understanding the homework assignment and not just having the answer will be critical then. This is why Henry didn't address your answer. It's not about right or wrong; it's about learning.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:
Seetharaman: We like to help people figure out how to solve problems and reason through them. After all - you won't be there when Manepalli is on the job. Understanding the homework assignment and not just having the answer will be critical then. This is why Henry didn't address your answer. It's not about right or wrong; it's about learning.


Yes Understand. My Appologies
 
manepalli rajesh
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks a lot to make my self learning while i am facing problems.


when i am entering any spaces it should not allow me right. but i wasted a lot of in this. if i put like in the following way , i would have saved a lot of time.


but nobody given this. i know above also should work. but it is not working properly.
we are in the forum to get the help about this kind of problems. thanks a lot.


[HENRY: Fixed code tags]
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"[^\\s]+" means one or more of characters that are not whitespaces. If you uses the matches() method, it means that every character must not be a whitespace. Any character that *is* a whitespace will cause a failure to match.

Is this what you want? If not, can you show code that shows what you are doing?

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!