This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Regular expression to match patterns

Help for those learning Tcl or writing their own scripts.
Post Reply
p
passion
Voice
Posts: 3
Joined: Mon Apr 26, 2010 7:48 pm

Regular expression to match patterns

Post by passion »

Hi guys,

I just would like to know how to write TCL script using proc for regexp matching the following pattern to match the user i/p


XYZ XZZ XZY XAX

Thank you
User avatar
arfer
Master
Posts: 436
Joined: Fri Nov 26, 2004 8:45 pm
Location: Manchester, UK

Post by arfer »

[11:00] <@arfer> % return [regexp -- {(\d{1,3}\.){3}\d{1,3}} 123.235.26.5]
[11:00] <@Baal> 1
[11:00] <@arfer> % return [regexp -- {(\d{1,3}\.){3}\d{1,3}} 123.235.2a.5]
[11:00] <@Baal> 0

Don't forget that this is not sufficient by itself to determine if a string is a valid ipv4 numeric ip. You will have to split the string at '.' and test if each octet is <= 255.

I suppose life gets even more difficult if you also want to determine if it is a valid external IP, for example not loopback or private lan. I have some code somewhere for these tests. If you have any interest, I will try to dig it out.
I must have had nothing to do
Post Reply