I need help with a regexp to find out the ip address which can possibly be present in a URL.
The URLs can be in any of the following form
<domain>?a=12345&d=somestring1
<domain>?c=10.10.10.100&d=somestring1
<domain>?a=12345&b=somestring1&c=10.1.2.4d=somestring2
<domain>?a=12345&c=10.1.2.4&b=somestring1&d=somestring2
The rules
1) "c=" may not always be present
2) "c=" can be anywhere in the string but not the last, last is always "d"
3) If "c=" is present I need the value of c which should be an ip address.
Yes, I think you should be able to apply the logic to TCL commands, since TCL supports regular expressions. I don't know anything about the TCL regexp command, so cannot help with details. Any chance TCL can call sed?
Yes, you can get the ip address, minus the c= part, by moving c= outside of the saved group, as follows:
$ sed -n "s/.*c=\([^&]*\).*d=.*/\1/p" urls
10.10.10.100
10.1.2.4
10.1.2.4