mIRC Homepage
Posted By: NightChillz regex help - 14/07/07 09:40 PM
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
Posted By: qwerty Re: regex help - 14/07/07 10:00 PM
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.
Posted By: NightChillz Re: regex help - 14/07/07 10:05 PM
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^^^
Posted By: qwerty Re: regex help - 14/07/07 10:17 PM
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)
Posted By: NightChillz Re: regex help - 14/07/07 10:18 PM
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
Posted By: NightChillz Re: regex help - 14/07/07 10:22 PM
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?
Posted By: qwerty Re: regex help - 14/07/07 10:29 PM
& only appears in versions.txt (item 73 of v5.0).
Posted By: NightChillz Re: regex help - 14/07/07 10:37 PM
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?
Posted By: qwerty Re: regex help - 14/07/07 11:30 PM
Anything inside \Q...\E is treated literally, ie special characters lose their meaning and are treated as plain text.
Posted By: Sat Re: regex help - 14/07/07 11:33 PM
nuh-uh, it's listed under /help on text
Posted By: qwerty Re: regex help - 14/07/07 11:37 PM
I did a search on "wildcard" in the help file and (thought I) checked all matches, yet I managed to miss it mad
Posted By: NightChillz Re: regex help - 15/07/07 12:35 AM
ic, well thanks for the info smile
© mIRC Discussion Forums