TCL scripting - searching for a IP address in a string

Hi All,

Can anyone please help me with the regular expression/code snippet to search for an IP address in a string with Tcl scripting.

Example string
"OSPF_NBRUP OSPF neighbor 16.138.181.15 (realm ospf-v2 e1-0/0/0:37.0 area 0.0.0.0) state changed from Full to Down due to KillNbr"

In the above string i want to find IP 16.138.181.15

Something like this:

#!/usr/bin/tclsh 

set string "OSPF_NBRUP OSPF neighbor 16.138.181.15 (realm ospf-v2 e1-0/0/0:37.0 area 0.0.0.0) state changed from Full to Down due to KillNbr"

regexp {(?:\d+\.){3}\d+} $string matched

puts "matched is $matched"

It produces the following output:

% ./s  
matched is 16.138.181.15

what does the below mean ... I am new in TCL and hope to benefit from this ...

{(?:\d+\.){3}\d+}

---------- Post updated at 07:26 AM ---------- Previous update was at 07:25 AM ----------

and is "puts" a command or just a word?

It's a regular expression that matches a sequence of 3 atoms of
one or more digit(s) followed by a literal dot[1] followed by one or more digit(s).

puts is a command.

[1]

Thanks man
BR

One more thing ..can you please recommend to me some books related to TCL & TK

---------- Post updated at 07:01 AM ---------- Previous update was at 06:58 AM ----------

Thanks in advance

I'm quite new to TCL too. I want to learn the language because of expect, which seems very interesting to me.
I purchased Exploring Expect on amazon and there is a quick TCL tutorial at the beginning of the book.
You could even consult it online on Google books.

I should add that the TCL group on USENET (comp.lang.tcl) is also a great resource.

Thanks a lot radoulov :b: