问题
I am trying to search a text file that will return a result if more than one word is found in that line. I don't see this explained in the documentation and I have tried various loops with no success.
What I would like to do is something similar to this:
$read(name.txt, s, word1|word2|word3)
or even something like this:
$read(name.txt, w, word1*|*word2*|*word3)
I don't know RegEx that well so I'm assuming this can be done with that but I don't know how to do that.
回答1:
The documentation in the client self is good but I also recommend this site: http://en.wikichip.org/wiki/mirc. And with your problem there is a nice article : http://en.wikichip.org/wiki/mirc/text_files
All the info is taken from there. So credits to wikichip.
alias testForString {
while ($read(file.txt, nw, *test*, $calc($readn + 1))) {
var %line = $v1
; you can add your own words in the regex, seperate them with a pipe (|)
noop $regex(%line,/(word1|word2|word3|test)/))
echo -a Amount of results: $regml(0)
}
}
$readn
is an identifier that returns the line that $read()
matched. It is used to start searching for the pattern on the next line. Which is in this case test
.
In the code above, $readn
starts at 0. We use $calc()
to start at line 1. Every match $read()
will start searching on the next line. When no more matches are after the line specified $read
will return $null
- terminating the loop.
The w
switch is used to use a wildcard in your search
The n
switch prevents evaluating the text it reads as if it was mSL code. In almost EVERY case you must use the n switch. Except if you really need it. Improper use of the $read() identifier without the 'n' switch could leave your script highly vulnerable.
The result is stored in a variable named %line
to use it later in case you need it.
After that we use a noop
to execute a regex to match your needs. In this case you can use $regml(0)
to find the amount of matches which are specified in your regex search. Using an if-statement you can see if there are two or more matches.
Hope you find this helpful, if there's anything unclear, I will try to explain it better.
EDIT
@cp022 I can't comment, so I'll post my comment here, so how does that help in any way to read content from a text file?
来源:https://stackoverflow.com/questions/36543839/mirc-search-for-multiple-words-in-text-file