Whitespace using Regular Expressions

G

Guest

Hi,

I have a Regular Expression that will match the format a
user provides in a textbox.

Ex. Brown,Joe in the textbox

I would like the expression to have both whitespace and
non-whitespace options after the comma.

Any suggestions or maybe a different Regular Expression
that allows both non-whitespace and whitespace options
after a comma would be appreciated.

Thanks.

bebop

The Regular Expression I'm using:

Regex regex4 = new Regex("^[A-Z][a-zA-Z]*\\,+\\S+(|\\S)+
([a-zA-Z]*)$");
 
J

Jerry III

Just add \s* around the comma (escaping the \ as you've done for your other
\). Just out of curiousity - why are you escaping comma? And are yous ure
you want to allow multiple commas? And I don't even want to know why you
check for non white space characters followed by letters, and why you
capture the second match of non white space characters following one or more
non white space characters but not the first one and not the letters
following.

Jerry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top