Whitespace using Regular Expressions

  • Thread starter Thread starter Guest
  • Start date Start date
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]*)$");
 
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
 
Back
Top