mIRC Homepage
Posted By: mattiaz regex help plz - 03/02/04 12:39 AM
hi. if any1 could help me with this i would really appreciate it smile

i'm making a search script which searches a txt file using /filter,
but i only want it to match the text efter the last backslash..

lets say my txtfile has this in it.
c:\test
c:\bla\test.txt
c:\TesT\bla.txt
c:\program files\Test
c:\program files\bla\TEST.txt
c:\program files\test\Bla.txt

so right now /search test would match all these lines but i just want it to match
c:\test
c:\bla\test.txt
c:\program files\Test
c:\program files\bla\TEST.txt

hopefully this is possible using filter and regex.

// mattiaz
Posted By: qwerty Re: regex help plz - 03/02/04 01:34 AM
Assuming we're in /search alias, use this pattern with /filter:
Code:
/\\[^\\]* $+ $1 $+ [^\\]*$/
Posted By: mattiaz Re: regex help plz - 03/02/04 02:10 AM
tnx for the reply which works great for what i asked for,
but not exactly how i wanted it to work.. smile
perhaps i should have specified more

my /filter command now is

filter -ffct 1 32 file.txt filtered.txt %search

where %search = $+(*,$replace($1-,$chr(32),$chr(42)),*)

so /search test would make %search *test*
and /search t e s t would make %search *t*e*s*t*

also i would want it to not be case-sensitive..

// mattiaz
Posted By: qwerty Re: regex help plz - 03/02/04 02:24 AM
Code:
var %search = $replace($1-,^,\^,$,\$,.,\.,[,\[,$chr(40),\ $+ $chr(40),$chr(41),\ $+ $chr(41),+,\+,$chr(123),\ $+ $chr(123),$chr(32),*,*,.*,?,.)
filter -ffcgt 1 32 file.txt filtered.txt /(?i)\\[^\\]* $+ %search $+ [^\\]*$/
This uses regex to imitate wildcard behaviour. The big replace is used to replace characters that are considered special in regex with their escape sequences, so that the only "special" chars are * and ?
Posted By: mattiaz Re: regex help plz - 03/02/04 02:48 AM
works better but still not perfect..
while searching for just one word it works..

but "/search file test"
matches c:\program files\test.txt
which it shouln't..

// mattiaz
Posted By: qwerty Re: regex help plz - 03/02/04 03:05 AM
Oops, you're right, my mistake. Try this:
Code:
var %search = $replace($1-,^,\^,$,\$,.,\.,[,\[,$chr(40),\ $+ $chr(40),$chr(41),\ $+ $chr(41),+,\+,$chr(123),\{,$chr(32),*,*,[^\\]*,?,[^\\])
filter -ffcgt 1 32 file.txt filtered.txt /(?i)\\[^\\]* $+ %search $+ [^\\]*$/
Posted By: mattiaz Re: regex help plz - 03/02/04 03:09 AM
tnx alot qwerty, works great now! laugh

// mattiaz
© mIRC Discussion Forums