mIRC Home    About    Download    Register    News    Help

Print Thread
Possible regex help #201135 20/06/08 06:49 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
I was wondering if there would be a way to use regex (since im thinking its needed) to match all words in a sentence let me show in detail (somewhat of a encoding string with matchtext)

Thejappleu98falls9nfjfar28nkjfromjskfthe87asftree.

The apple falls far from the tree.

Would there be a way that I have a large list of sentences that should match that in text format is there a way to kind of loop through a text file using regex to see which of the strings match perfectly word for word in the encoded message?

like

Alias loopct {
var %x = 1
while (%x <= $lines(strGet.txt)) {
if ($regex($read(strget.txt,%x)blahblahblah == 1 or blah blah) { REMOVE data that's incorrect and replace with correct data store it to global variable }
inc %x
}
}

So basically I need to call back at anytime I need it the string it found in the strget.txt file, so something like $regml would have to return me the match it found so i can use it later in the script.



Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Possible regex help [Re: Lpfix5] #201139 20/06/08 09:28 PM
Joined: Jul 2006
Posts: 3,923
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,923
I'm not sure about what you want, but i think you should user /filter with -k and g switch, call the alias you specified when matching a line in the text file for the pattern
How is your text file ? is there the string form or the right sentence ?

Edit : hope this help :

Code:
alias matchfile {
  filter -kg file.txt mfile_cb $+(/,$replacex($1-,$chr(32),.*,.,\.),/)
}
alias mfile_cb {
  echo -a matched file : $1-
}
file.txt contain thing like Thejappleu98falls9nfjfar28nkjfromjskfthe87asftree.
type /matchfile "sentence" to use it
for exemple /matchfile The apple falls far from the tree. will match Thejappleu98falls9nfjfar28nkjfromjskfthe87asftree.


Last edited by Wims; 20/06/08 09:52 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Re: Possible regex help [Re: Wims] #201158 21/06/08 01:45 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
I need more of a search that's automatically done

On text event

<User> Can you guess the phrase: thesjaifsun87safsetsat934jdnightjis

On *:text:*:#:{
if (User isin $nick) && ($5 == phrase:) { %c.t1 = $6- }
}

now the string is stored as a global varilable now what needs to automatically be performed is a search on my txt file called strget.txt to compare if it can find anything in my file that matches 100% then say the data that it matched to the channel.

my text file structure is simple and basic

Example:

The apple falls far from the tree
The boy who cried wolf
The boy who knows too much

now this list is about 300KB yes ouch. Now I know looping through this would take it's toll on time but maybe I can pre-load the txt file somewhere and use it like in a window, i just can't think properly what would be the suitable way and how to use regex to compare 100% match and only then will it say in channel what it found else nothing is displayed.



Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Possible regex help [Re: Lpfix5] #201161 21/06/08 03:20 PM
Joined: Jul 2006
Posts: 3,923
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,923
You need to apply a regex match but the pattern depend about each line in your file, and as you said, looping through this will be slow, but /filter might be faster than a while.Use filter -k to match all line first, and then use $regex in the alias that will be called to know if it's an exactly match (replace the space by .+ and escape all the period in the line).I don't think there is a better way to do this.



#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Re: Possible regex help [Re: Lpfix5] #201163 21/06/08 03:47 PM
Joined: Oct 2003
Posts: 3,918
A
argv0 Offline
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Sounds like you're using this script to cheat a trivia style game, but I'll bite:

You don't need to filter to an alias that uses regex, you just need to filter with the match as your %c.t1 thing

Code:
ON *:TEXT:*:#:{ 
  if (User == $nick) && ($5 == phrase:) { 
    filter -fk file.txt matchtest $6-
  }
}
alias matchtest { msg # Matched: $1- }


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Re: Possible regex help [Re: argv0] #201198 22/06/08 11:13 AM
Joined: Jul 2006
Posts: 3,923
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,923
I've tried what you said but it does not work.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Re: Possible regex help [Re: argv0] #201364 26/06/08 07:41 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
its not trivia, you can come on my server in channel FFXVI to see :P


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Possible regex help [Re: Lpfix5] #201373 26/06/08 11:20 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
argv0 its not working, I wouldnt see how neither, since /filter -fk is basic f file to file or file to alias

while the incomming string %ct.1 is still blahthissajsfisjjasfofhow

this is how


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Possible regex help [Re: Lpfix5] #201383 27/06/08 02:03 AM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
argv0 its bugging me I keep looking at your thread over and over and I dont know how this could work without matching the string in a regex format

like simple $regex($6-,/(all|these|words)/g) I want to know a fast way to scan my text file which would be filter but how to use it in a on text event and knowing what string is what string and how to match it

So when i get my ON TEXT event the message is decoded im looking for a way to AUTO decode it

so like

on *:TEXT:*:#:{
if ($nick == User) && ($5 = meh) {
SOMEHOW loop through file.txt in a regex format for a positive match if existing...
}
}

So again $6 is always a constant variable change and is always in the format of jhfdsjijWORDjhawijajiWORDwijdwjiwWORD thats why I need a way too loop through the text file to find a positive match if so then display it back


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Possible regex help [Re: Lpfix5] #201389 27/06/08 04:42 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
From what I can understand of your request:

You have a text file containing phrases.
You have a string of text from some source (onTEXT).
You want to match the lines in the text file to whatever your string is.

If this is correct..

My suggestion is to load the lines into a hash table with the item as the regex/wildcard you want to search, and the data as the line you want to display. A simple $replace can convert spaces/etc to * (wildcard) or .* (regex) in your table. Testing may be required to determine if one is quicker than the other. Example:

(regex)
(?i)^this.*is.*your.*first.*line$ = this is your first line

(wildcard)
this*is*your*first*line = this is your first line

etc.

Then you can do a $hfind search through the whole table for any/all matches.

Code:

%text = this298374is923847your982734first92374line
%item = $hfind(yourtable,%text,1,R)
%data = $hget(yourtable,%item)

(change R to W for wildcard match)


(example only)

-genius_at_work

Last edited by genius_at_work; 27/06/08 04:45 AM.
Re: Possible regex help [Re: genius_at_work] #201404 27/06/08 03:36 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Let me explain it a little better

on *:TEXT:*:#FFVXI:{
if ($nick == User) {
%globalvar = $6
}
}

now %globalvar contains line this292is98323an0293023example

now apart from storing the global variable in the same on text event I need a way to loop through (FILE.TXT) and match $6 or %globalvar for that matter.

So this means I do not have a static search I can do, this is always a variable change meaning I would have to loop through every single phrase in my .txt file (300KB) and perform some kind of regex match till it finds all words that match in the text file and return it to me.

So again when i get the string its encoded, my text file has a decoded version of all these strings thats why im asking if theres way to use regex or a better way that is fast that can compare all LINES in txt file in a jippy vs. %globalvar or $6


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Possible regex help [Re: Lpfix5] #201405 27/06/08 03:55 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Wims and genius_at_work already explained how you might go about it. Here's a concrete example:
Code:
on *:TEXT:*:#FFVXI:{
  if $0 > 5 && $nick == User {
    set -u %globalvar $6
    filter -fk file.txt blah
  }
}
alias blah {
  if $replace(* $+ $1*,$chr(32),*) iswm %globalvar {
    echo -a $1
  }
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Possible regex help [Re: qwerty] #201406 27/06/08 05:22 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline OP
Hoopy frood
OP Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
I get it now, sorry and thank you all. Works perfect


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }