mIRC Homepage
Posted By: AWEstun HASH: $hfind - 01/07/08 01:45 AM
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
Posted By: RusselB Re: HASH: $hfind - 01/07/08 02:57 AM
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
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 03:08 AM
Originally Posted By: RusselB
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.
Posted By: genius_at_work Re: HASH: $hfind - 01/07/08 03:17 AM
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
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 03:38 AM
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
Posted By: genius_at_work Re: HASH: $hfind - 01/07/08 03:54 AM
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
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 03:59 AM
Originally Posted By: 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.
Posted By: genius_at_work Re: HASH: $hfind - 01/07/08 04:22 AM
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i
%entry2 = $hfind(iptracker,%re,%c,r).data

-genius_at_work
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 04:28 AM
Originally Posted By: 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.
Posted By: qwerty Re: HASH: $hfind - 01/07/08 11:28 AM
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/)
Posted By: qwerty Re: HASH: $hfind - 01/07/08 11:32 AM
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.
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 06:32 PM
Originally Posted By: qwerty
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.
Posted By: genius_at_work Re: HASH: $hfind - 01/07/08 06:42 PM
My error:

I meant (^|\s) and (\s|$)


-genius_at_work
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 07:02 PM
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.
Posted By: genius_at_work Re: HASH: $hfind - 01/07/08 07:27 PM
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
Posted By: AWEstun Re: HASH: $hfind - 01/07/08 07:44 PM
Originally Posted By: 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.
© mIRC Discussion Forums