Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,

Please will you provide regular express for the below.

should accept alphabets and with only one space but not in begin and end; no number and special chars allowed


The following should pass:
"A"
"A B"
"Hello There"

The following should fail:

" A"
"A "
" A "
" test"

What I have tried:

"^([a-zA-Z]+\S{0,1})*[a-zA-Z]+$"
Posted
Updated 20-Jun-17 23:48pm

1 solution

Quote:
^([a-zA-Z]+\S{0,1})*[a-zA-Z]+$

As far as I can see, your RegEx is correct. You need to provide more informaions on how it fail.

Just a few interesting links to help building and debugging RegEx.
Here is a link to RegEx documentation:
perlre - perldoc.perl.org[^]
Here is links to tools to help build RegEx and debug them:
.NET Regex Tester - Regex Storm[^]
Expresso Regular Expression Tool[^]
This one show you the RegEx as a nice graph which is really helpful to understand what is doing a RegEx:
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]
 
Share this answer
 

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