|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
In my tracker program I have a matchuser routine that takes all the saved IP's (data) in the user's name (item) and searches for the same individual IP's in other items. The problem is I'm using a wildcard search in $hfind and if the current searched IP is something like 1.2.3.4 it will also match to 1.2.3.40 (1.2.3.4*) and thus give additional incorrect matches. How do I use $hfind to match for the exact search item?
This is the current 'wildcard' $hfind :
var %entry2 = $hfind(iptracker,$+(*,%entry,*),%c,w).data
I've tried the following to search for the exact string, but it doesn't work:
var %entry2 = $hfind(iptracker,%entry,%c).data
|
|
|
|
Joined: Aug 2004
Posts: 7,168
Hoopy frood
|
Hoopy frood
Joined: Aug 2004
Posts: 7,168 |
You might try something like var %entry2 = $hfind(iptracker,$+(*,$chr(32),%entry,$chr(32),*),%c,w).data
This presumes that each proper ip address is space separated in the data. eg: 1.2.3.4 1.2.3.40 1.25.36.495
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
You might try something like var %entry2 = $hfind(iptracker,$+(*,$chr(32),%entry,$chr(32),*),%c,w).data
This presumes that each proper ip address is space separated in the data. eg: 1.2.3.4 1.2.3.40 1.25.36.495 I tried something like your example, but w/o the wildcards on the end. Your example didn't work either. Hum.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
I would use a regex search rather than a wildcard in this situation:
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i echo -a $hfind(iptracker,%re,%c,r).data
(untested)
[\s^] = match a space or beginning of line [\s$] = match a space or end of line
\. = escape . characters to \. ( . has special meaning in regex)
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
Actually, var %entry is the exact string that needs to be used for the search, so how would I use $hfind with just %entry ?
The following does not work:
var %entry2 = $hfind(iptracker,%entry,%c).data
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
If you want to find an entry that contains ONLY the text within %entry, you can do a wildcard search without wildcards.
If the hash table were like this:
item1: 1.2.3.40 item2: 1.2.3.4 item3: 11.2.3.4
and %entry = 1.2.3.4
Then: $hfind(table,%entry,%c,w) would be used to match ONLY item2.
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
If you want to find an entry that contains ONLY the text within %entry, you can do a wildcard search without wildcards.
If the hash table were like this:
item1: 1.2.3.40 item2: 1.2.3.4 item3: 11.2.3.4
and %entry = 1.2.3.4
Then: $hfind(table,%entry,%c,w) would be used to match ONLY item2.
-genius_at_work I tried: var %entry2 = $hfind(iptracker,%entry,%c,w).data but that didn't work either. It's not giving %entry2 the item name of the match. Im not sure if it matters, but there are multiple IP's per item.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i %entry2 = $hfind(iptracker,%re,%c,r).data
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i %entry2 = $hfind(iptracker,%re,%c,r).data
-genius_at_work That didn't work either.
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
Assertions/anchors do not match single characters, so they cannot be put in a character class. This should work:
var %re = $+(/\b\Q,%entry,\E\b/)
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
The reason why RusselB's suggestion doesn't (always) work is that IP addresses aren't always surrounded by spaces in your data: the first and last IPs have a space only on one side.
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
The reason why RusselB's suggestion doesn't (always) work is that IP addresses aren't always surrounded by spaces in your data: the first and last IPs have a space only on one side. Thats what I was thinking too.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
My error:
I meant (^|\s) and (\s|$)
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
Okay I tried this and it does not work:
var %re = $+(/\b\Q,%entry,\E\b/) var %entry2 = $hfind(iptracker,$+(*,%re,*),%c,w).data
It's not returning any names.
|
|
|
|
Joined: Oct 2005
Posts: 1,671
Hoopy frood
|
Hoopy frood
Joined: Oct 2005
Posts: 1,671 |
You have to use the regex switch in your $hfind. Also, you don't need any *, as this isn't a wildcard search.
var %entry2 = $hfind(iptracker,%re,%c,r).data
-genius_at_work
|
|
|
|
Joined: May 2008
Posts: 329
Fjord artisan
|
OP
Fjord artisan
Joined: May 2008
Posts: 329 |
You have to use the regex switch in your $hfind. Also, you don't need any *, as this isn't a wildcard search.
var %entry2 = $hfind(iptracker,%re,%c,r).data
-genius_at_work It works now, but it majorly slowed down the search. It's added on about 2-3 seconds per 5-7 IP searches.
|
|
|
|
|