Home All Groups Group Topic Archive Search About
Author
25 Mar 2005 12:47 PM
Mike P
I have a regular expression that I use on text boxes where I want to
limit the user to letters a-z and spaces.  I now need to allow
characters such as ö, ä and å (Nordic characters).  Does anybody know
how to do this in a regular expression?  Here is my current standard
regular expression :

^[a-zA-Z\s]+$

Any assistance would be really appreciated.


Cheers,

Mike


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Author
25 Mar 2005 4:00 PM
Chris R. Timmons
Mike P <m**@telcoelectronics.co.uk> wrote in
news:e2OmRjTMFHA.732@TK2MSFTNGP12.phx.gbl:

> I have a regular expression that I use on text boxes where I
> want to limit the user to letters a-z and spaces.  I now need to
> allow characters such as ö, ä and å (Nordic characters).  Does
> anybody know how to do this in a regular expression?  Here is my
> current standard regular expression :
>
> ^[a-zA-Z\s]+$
>
> Any assistance would be really appreciated.

Mike,

You can add those Nordic characters to the existing character class:

  ^[a-zA-Zöäå\s]+$

Alternately, you can match all of the characters in a Unicode
"block".  Nordic characters are part of the "Latin-1 Supplement"
block, which are characters in the range of 0080-00FF:

  ^[a-zA-Z\u0080-\u00FF\s]+$

Unicode code charts can be found here:
  http://www.unicode.org/charts/

Where Is My Character?
  http://www.unicode.org/standard/where/

Unicode and Regular Expressions:
  http://www.unicode.org/unicode/reports/tr18/

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Author
26 Mar 2005 3:51 AM
Ryan Learns Sharp
I also met with a problem with RegEx.

I want to match such pattern "position:12", and get the substring "12" from
the pattern. What I used in C# is:

Regex regex = new Regex( "position:(?<num>)" );

However, when I use the statement:

string result = match.Groups["num"].Value;

in which match is a Match object that is generated by
regex.Match(sourceString); what I got is a NULL string.

Could anyone explain why? Thanks in advance!
Author
26 Mar 2005 10:11 AM
Chris R. Timmons
"=?Utf-8?B?UnlhbiBMZWFybnMgU2hhcnA=?="
<RyanLearnsSh***@discussions.microsoft.com> wrote in
Show quote
news:9E9316C3-CE2D-4BA7-89E1-90260BBAC518@microsoft.com:

> I also met with a problem with RegEx.
>
> I want to match such pattern "position:12", and get the
> substring "12" from the pattern. What I used in C# is:
>
> Regex regex = new Regex( "position:(?<num>)" );
>
> However, when I use the statement:
>
> string result = match.Groups["num"].Value;
>
> in which match is a Match object that is generated by
> regex.Match(sourceString); what I got is a NULL string.

The (?<num>) capture group does not have any character matching
specifiers.  If you want it to capture a number after the colon,
change it to this:

  Regex regex = new Regex( "position:(?<num>\d+)" );

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Author
26 Mar 2005 3:09 PM
Ryan Learns Sharp
Thanks Chris !

You are right and I used "position:(?<num>\\d+)" to get the correct data~

I referred to the MSDN, and learned about Group :)

Show quote
"Chris R. Timmons" wrote:

> "=?Utf-8?B?UnlhbiBMZWFybnMgU2hhcnA=?="
> <RyanLearnsSh***@discussions.microsoft.com> wrote in
> news:9E9316C3-CE2D-4BA7-89E1-90260BBAC518@microsoft.com:
>
> > I also met with a problem with RegEx.
> >
> > I want to match such pattern "position:12", and get the
> > substring "12" from the pattern. What I used in C# is:
> >
> > Regex regex = new Regex( "position:(?<num>)" );
> >
> > However, when I use the statement:
> >
> > string result = match.Groups["num"].Value;
> >
> > in which match is a Match object that is generated by
> > regex.Match(sourceString); what I got is a NULL string.
>
> The (?<num>) capture group does not have any character matching
> specifiers.  If you want it to capture a number after the colon,
> change it to this:
>
>   Regex regex = new Regex( "position:(?<num>\d+)" );
>
> --
> Hope this helps.
>
> Chris.
> -------------
> C.R. Timmons Consulting, Inc.
> http://www.crtimmonsinc.com/
>
Author
26 Mar 2005 5:00 PM
Jay B. Harlow [MVP - Outlook]
Mike,
In addition to the other comments.

Have you considered "word characters"? the \w escape?

    ^[\w\s]+$

Which unfortunately includes numbers.

You could try the unicode block character classes (based on the \w escape):

    ^[\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Pc}]. \s]+$

\p{Ll} is all lower case leters & not just a-z...


Expresso & RegEx Workbench both have wizards of varying degrees to help you
build your expression, plus they allow you to test your expressions, also
the analyzer/interpreter in each is rather handy.

Expresso:
http://www.ultrapico.com/Expresso.htm

RegEx Workbench:
http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=c712f2df-b026-4d58-8961-4ee2729d7322A

tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconRegularExpressionsLanguageElements.asp

Hope this helps
Jay


Show quote
"Mike P" <m**@telcoelectronics.co.uk> wrote in message
news:e2OmRjTMFHA.732@TK2MSFTNGP12.phx.gbl...
>I have a regular expression that I use on text boxes where I want to
> limit the user to letters a-z and spaces.  I now need to allow
> characters such as ö, ä and å (Nordic characters).  Does anybody know
> how to do this in a regular expression?  Here is my current standard
> regular expression :
>
> ^[a-zA-Z\s]+$
>
> Any assistance would be really appreciated.
>
>
> Cheers,
>
> Mike
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!

AddThis Social Bookmark Button