mIRC Home    About    Download    Register    News    Help

Print Thread
#201587 01/07/08 01:45 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
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


I registered; you should too.
AWEstun #201588 01/07/08 02:57 AM
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
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

RusselB #201589 01/07/08 03:08 AM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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.


I registered; you should too.
AWEstun #201590 01/07/08 03:17 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
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


I registered; you should too.
AWEstun #201593 01/07/08 03:54 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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.


I registered; you should too.
AWEstun #201596 01/07/08 04:22 AM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
var %re = /[\s^] $+ $replace(%entry,.,\.) $+ [\s$]/i
%entry2 = $hfind(iptracker,%re,%c,r).data

-genius_at_work

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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.


I registered; you should too.
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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/)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
AWEstun #201616 01/07/08 11:32 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
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.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #201637 01/07/08 06:32 PM
Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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.


I registered; you should too.
qwerty #201638 01/07/08 06:42 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
My error:

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


-genius_at_work

Joined: May 2008
Posts: 329
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
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.


I registered; you should too.
AWEstun #201645 01/07/08 07:27 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
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
A
AWEstun Offline OP
Fjord artisan
OP Offline
Fjord artisan
A
Joined: May 2008
Posts: 329
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.


I registered; you should too.

Link Copied to Clipboard