Click here to Skip to main content
15,886,037 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

[0-9a-zA-z]:

This regular expression is for validating a string with one charecter or number and a colon at the end.

For Eg: 1:, a:, c:

How can I rewrite this regualr expression to accomodate any no. of charecter/ numbers infront of the colon (:).


Thanks in advance.
Posted

1 solution

Either
[0-9a-zA-Z]+:
for "one or more", or
[0-9a-zA-Z]*:
for "zero or more"
But you may find this better:
\w+:
for "one or more", or
\w*:
for "zero or more"

"\w" is the equivalent of "[0-9a-zA-Z_]"
 
Share this answer
 
Comments
CPallini 22-Apr-14 3:42am    
5.
Ajith K Gatty 22-Apr-14 3:58am    
\w+: is a best solution.
aswathy.s.88 22-Apr-14 4:16am    
Thank you so much OriginalGriff991 ....

And how to include special charecters too infront of the colon?
OriginalGriff 22-Apr-14 4:19am    
Depends on what special characters you want! :laugh:
aswathy.s.88 22-Apr-14 5:00am    
I want to use all teh special charecters.... so how will be the RegExp?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900