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
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
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.
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
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
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
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.
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i
%entry2 = $hfind(iptracker,%re,%c,r).data
-genius_at_work
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i
%entry2 = $hfind(iptracker,%re,%c,r).data
-genius_at_work
That didn't work either.
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/)
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.
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.
My error:
I meant (^|\s) and (\s|$)
-genius_at_work
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.
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
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.