473,386 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

regular expression pattern needed

I need to strip the ()- and spaces from a telephone number. What is the
regular express pattern for this? "\(\)-"?

thanks
Nov 20 '05 #1
5 2611

Try this:

PhoneNumber = Regex.Replace(PhoneNumber, "[()-]","")

Brian Davis
www.knowdotnet.com
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I need to strip the ()- and spaces from a telephone number. What is the
regular express pattern for this? "\(\)-"?

thanks

Nov 20 '05 #2
that works. this too:

'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "[^0-9]","")

"Brian Davis" <@> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Try this:

PhoneNumber = Regex.Replace(PhoneNumber, "[()-]","")

Brian Davis
www.knowdotnet.com
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I need to strip the ()- and spaces from a telephone number. What is the
regular express pattern for this? "\(\)-"?

thanks


Nov 20 '05 #3
Craig,
Which can be shorted to:
'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "\D","")
However, yours & mine will clobber phone numbers that are words:

1-800-FOR-HELP

Hope this helps
Jay

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl... that works. this too:

'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "[^0-9]","")

"Brian Davis" <@> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Try this:

PhoneNumber = Regex.Replace(PhoneNumber, "[()-]","")

Brian Davis
www.knowdotnet.com
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
I need to strip the ()- and spaces from a telephone number. What is the regular express pattern for this? "\(\)-"?

thanks



Nov 20 '05 #4
Jay-

What does the \D mean?

Thanks,

Craig

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uc**************@TK2MSFTNGP09.phx.gbl...
Craig,
Which can be shorted to:
'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "\D","")


However, yours & mine will clobber phone numbers that are words:

1-800-FOR-HELP

Hope this helps
Jay

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
that works. this too:

'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "[^0-9]","")

"Brian Davis" <@> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...

Try this:

PhoneNumber = Regex.Replace(PhoneNumber, "[()-]","")

Brian Davis
www.knowdotnet.com
"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:OV**************@TK2MSFTNGP10.phx.gbl...
> I need to strip the ()- and spaces from a telephone number. What is the > regular express pattern for this? "\(\)-"?
>
> thanks
>
>



Nov 20 '05 #5
Craig,
What does the \D mean? "\D" effectively means "[^0-9]"

Per:
http://msdn.microsoft.com/library/de...terClasses.asp

\D : Matches any nondigit. Equivalent to \P{Nd} for Unicode and [^0-9] for
non-Unicode, ECMAScript behavior.

Most of the time I prefer the character codes \d over [0-9] or \D over
[^0-9] as they are more internationalized (they will work for any Unicode
numeric value, not just the ANSI 0 to 9 characters. Also they tend to be
shorter ;-)

Hope this helps
Jay

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl... Jay-

What does the \D mean?

Thanks,

Craig

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message
news:uc**************@TK2MSFTNGP09.phx.gbl...
Craig,
Which can be shorted to:
'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "\D","")


However, yours & mine will clobber phone numbers that are words:

1-800-FOR-HELP

Hope this helps
Jay

"Craig Buchanan" <so*****@somewhere.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
that works. this too:

'strip anything that isn't a number
PhoneNumber = Regex.Replace(PhoneNumber, "[^0-9]","")

"Brian Davis" <@> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
>
> Try this:
>
> PhoneNumber = Regex.Replace(PhoneNumber, "[()-]","")
>
> Brian Davis
> www.knowdotnet.com
>
>
> "Craig Buchanan" <so*****@somewhere.com> wrote in message
> news:OV**************@TK2MSFTNGP10.phx.gbl...
> > I need to strip the ()- and spaces from a telephone number. What
is the
> > regular express pattern for this? "\(\)-"?
> >
> > thanks
> >
> >
>
>



Nov 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Tina Li | last post by:
Hello, I've been struggling with a regular expression for parsing XML files, which keeps giving the run time error "maximum recursion limit exceeded". Here is the pattern string: ...
1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
2
by: Johann Sijpkes | last post by:
Hi, Just before going mad I thought asking this newsgroup would be a good idea. I want to validate dates using a schema but somehow the regexp is not performed by the validator? (at w3c..). I...
26
by: Shannon Jacobs | last post by:
Sorry to ask what is surely a trivial question. Also sorry that I don't have my current code version on hand, but... Anyway, must be some problem with trying to do the negative. It seems like I get...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
2
by: Dan Schumm | last post by:
I'm relatively new to regular expressions and was looking for some help on a problem that I need to solve. Basically, given an HTML string, I need to highlight certain words within the text of the...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
6
by: rorymo | last post by:
I have a regular expression that allows only certain characters to be valid in an xml doc as follows: <xs:pattern value="^*" /> What I want to do is also allow any unicode character that is...
5
by: shawnmkramer | last post by:
Anyone every heard of the Regex.IsMatch and Regex.Match methods just hanging and eventually getting a message "Requested Service not found"? I have the following pattern: ^(?<OrgCity>(+)+),...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.