mIRC Home    About    Download    Register    News    Help

Print Thread
#180887 14/07/07 09:40 PM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
hey, this is whats going on... i have a string:

word1 word2 word3 word4 etc


and i have a word, lets say %word, what i'm trying to do, with regex is see if %word = word3 in my string

so far i have


//echo -a $regex(this word heading some ifno,/(\s.*){2}heading\s.*/gi)

which echos 1, however it also echo's 1 if there are more words between "this" and "heading", sorry i have been away for a while and am not quite back in the swing of things with regular expression, thanks for your help


note: i would need it to match regardless if the first tow words are digits or not, trying to get it to match like this:

starts with any two words digits or otherwize, third word is the one i want to compare, followed by one or more words, digits or otherwize

example:

1 10.00 matchtext more words


so prolly something like \w\wmatchtext\w

Last edited by NightChillz; 14/07/07 10:03 PM.
NightChillz #180889 14/07/07 10:00 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You don't need regex for that, you can do:
if ($gettok(string,3,32) == %word)

Doing it with regex would actually be more complex if the word you want to check is dynamic, like the %word variable you mentioned, because you'd have to escape any regex special characters that might be in %word or use $+(\Q,$replacecs(%word,\E,\E\\E\Q),\E) instead of %word in the pattern.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #180890 14/07/07 10:05 PM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
well actually i have data stored in a hash table, and i wanna know if any item contains <word> in the 3rd place of its data


$hfind(table,/regex/,0,r).data


note that i edited my first post^^^

Last edited by NightChillz; 14/07/07 10:07 PM.
NightChillz #180891 14/07/07 10:17 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Since word3 is going to be followed by one or more words, you can avoid regex again with something like:
$hfind(table,& & %word *,0,w)

The only limitation of the above is that %word cannot contain * or ? characters.

The regex equivalent would be
$hfind(table,/^\S+ \S+ $+(\Q,$replacecs(%word,\E,\E\\E\Q),\E) /i,0,r)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
NightChillz #180892 14/07/07 10:18 PM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
for now i have it working like this:

$hfind(tbl,* %var *,0,w).data

but thats non-regex and will match if data contains the word "%var" regardless of qwhere it appears, i need it to only match if "%var" is found as the 3rd word anywhere in the table, which is only possible with some sort of regex in the matchtext

qwerty #180894 14/07/07 10:22 PM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
Originally Posted By: qwerty
Since word3 is going to be followed by one or more words, you can avoid regex again with something like:
$hfind(table,& & %word *,0,w)

The only limitation of the above is that %word cannot contain * or ? characters.

The regex equivalent would be
$hfind(table,/^\S+ \S+ $+(\Q,$replacecs(%word,\E,\E\\E\Q),\E) /i,0,r)


was unaware of the & &, is this documented somewhere?

NightChillz #180895 14/07/07 10:29 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
& only appears in versions.txt (item 73 of v5.0).


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #180896 14/07/07 10:37 PM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
cool, maybe i should read that sometime, lol

thanks for your help qwerty, long time no see btw (B)

and 1 question, why do you have /Q, what does it mean? and the /E replace? in that regex you posted?

NightChillz #180903 14/07/07 11:30 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Anything inside \Q...\E is treated literally, ie special characters lose their meaning and are treated as plain text.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #180904 14/07/07 11:33 PM
Joined: Apr 2004
Posts: 871
Sat Offline
Hoopy frood
Offline
Hoopy frood
Joined: Apr 2004
Posts: 871
nuh-uh, it's listed under /help on text


Saturn, QuakeNet staff
Sat #180906 14/07/07 11:37 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
I did a search on "wildcard" in the help file and (thought I) checked all matches, yet I managed to miss it mad


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
qwerty #180919 15/07/07 12:35 AM
Joined: Dec 2002
Posts: 271
N
Fjord artisan
OP Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 271
ic, well thanks for the info smile


Link Copied to Clipboard