|
Joined: Dec 2002
Posts: 270
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 270 |
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.
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
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.
|
|
|
|
Joined: Dec 2002
Posts: 270
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 270 |
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.
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
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)
|
|
|
|
Joined: Dec 2002
Posts: 270
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 270 |
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
|
|
|
|
Joined: Dec 2002
Posts: 270
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 270 |
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?
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
& only appears in versions.txt (item 73 of v5.0).
|
|
|
|
Joined: Dec 2002
Posts: 270
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 270 |
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?
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
Anything inside \Q...\E is treated literally, ie special characters lose their meaning and are treated as plain text.
|
|
|
|
Joined: Apr 2004
Posts: 700
Hoopy frood
|
Hoopy frood
Joined: Apr 2004
Posts: 700 |
nuh-uh, it's listed under /help on text
Saturn, QuakeNet staff
|
|
|
|
Joined: Jan 2003
Posts: 2,125
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,125 |
I did a search on "wildcard" in the help file and (thought I) checked all matches, yet I managed to miss it 
|
|
|
|
Joined: Dec 2002
Posts: 270
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 270 |
ic, well thanks for the info 
|
|
|
|
|