| View previous topic :: View next topic |
| Author |
Message |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Tue Jun 05, 2007 12:51 am Post subject: Best way to match using regexp? |
|
|
I came up with this recently:
| Code: |
if {[regexp -nocase {012-?[0-9]{7}[^A-Z0-9+&@#/%?=~_|!:,.;]|013-?[0-9]{7}[^A-Z0-9+&@#/%?=~_|!:,.;]|014-?[0-9]{7}[^A-Z0-9+&@#/%?=~_|!:,.;]|016-?[0-9]{7}[^A-Z0-9+&@#/%?=~_|!:,.;]|017-?[0-9]{7}[^A-Z0-9+&@#/%?=~_|!:,.;]|019-?[0-9]{7}[^A-Z0-9+&@#/%?=~_|!:,.;]} $text]} {
|
The code looks blotty right. Okay the main idea behind this is to match cell phone numbers.
The cell operator numbers are: 012, 013, 014... and so on as you can see.
Then there is a 7 digit phone number after the cell operator number.
After the last digit (7th digit) of the phone number there shouldn't be any number.
The number can be like:
0126708090
or even like:
012-6708090
This piece of code looks very long and blotty to me, although it works. Any suggestions for improvement? _________________ ·awyeah·
==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
================================== |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Tue Jun 05, 2007 5:39 am Post subject: |
|
|
| Code: | | regexp {^01[234679]-?[0-9]{7}$} $number |
So the number must start with a number (0) and end with a number (exactly 7 numbers after the operator). _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Wed Jun 06, 2007 3:42 am Post subject: |
|
|
Thanks Sir_Fz that is exactly what I needed! Actually the "$" in the end did the trick, hehe  _________________ ·awyeah·
==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
================================== |
|
| Back to top |
|
 |
De Kus Revered One

Joined: 15 Dec 2002 Posts: 1361 Location: Germany
|
Posted: Thu Jun 07, 2007 6:05 am Post subject: |
|
|
thats strange, my cell phone number consists of 8 digits and has a 4 digit prefix number even without the country code. Is it supposed to match only local cellphone numbers? _________________ De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens... |
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Thu Jun 07, 2007 2:37 pm Post subject: |
|
|
Phone numbers differ from one country to another. For example, here in Lebanon a phone number is made up of 6 numbers, and our area code is made up of 2 numbers so it's +961-xx-xxxxxx. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
awyeah Revered One

Joined: 26 Apr 2004 Posts: 1580 Location: Switzerland
|
Posted: Mon Jun 11, 2007 2:15 am Post subject: |
|
|
Exactly, Sir_Fz is right. This only matches cellphone providers in Malaysia. They have a 3 digit operator code following a 7 digit individual number. The fixed line numbers are however different.
Here is what I use now:
| Code: |
if {[regexp {\x20(01[234679]-?[0-9]{7})\x20} $text]} {
|
_________________ ·awyeah·
==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
================================== |
|
| Back to top |
|
 |
|