By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,899 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,899 IT Pros & Developers. It's quick & easy.

regular expressions

P: n/a
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!
Nov 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Mike P <mr*@telcoelectronics.co.uk> wrote in
news:e2*************@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/
Nov 17 '05 #2

P: n/a
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!
Nov 17 '05 #3

P: n/a
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!
Nov 17 '05 #4

P: n/a
"=?Utf-8?B?UnlhbiBMZWFybnMgU2hhcnA=?="
<Ry*************@discussions.microsoft.com> wrote in
news:9E**********************************@microsof t.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/
Nov 17 '05 #5

P: n/a
"=?Utf-8?B?UnlhbiBMZWFybnMgU2hhcnA=?="
<Ry*************@discussions.microsoft.com> wrote in
news:9E**********************************@microsof t.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/
Nov 17 '05 #6

P: n/a
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 :)

"Chris R. Timmons" wrote:
"=?Utf-8?B?UnlhbiBMZWFybnMgU2hhcnA=?="
<Ry*************@discussions.microsoft.com> wrote in
news:9E**********************************@microsof t.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/

Nov 17 '05 #7

P: n/a
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 :)

"Chris R. Timmons" wrote:
"=?Utf-8?B?UnlhbiBMZWFybnMgU2hhcnA=?="
<Ry*************@discussions.microsoft.com> wrote in
news:9E**********************************@microsof t.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/

Nov 17 '05 #8

P: n/a
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/U...-4ee2729d7322A

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

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:e2*************@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!

Nov 17 '05 #9

P: n/a
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/U...-4ee2729d7322A

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

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay
"Mike P" <mr*@telcoelectronics.co.uk> wrote in message
news:e2*************@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!

Nov 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.