egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Best way to match using regexp?

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Tue Jun 05, 2007 12:51 am    Post subject: Best way to match using regexp? Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jun 05, 2007 5:39 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Wed Jun 06, 2007 3:42 am    Post subject: Reply with quote

Thanks Sir_Fz that is exactly what I needed! Actually the "$" in the end did the trick, hehe Razz
_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Thu Jun 07, 2007 6:05 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Jun 07, 2007 2:37 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Mon Jun 11, 2007 2:15 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber