|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
1. how can i know the position of \1 in the text ? so in $regsub(abcd,(b),\1,%x) \1 should replaced with something that will return 2 (cuz that's the position of b) 2. $regsub(abcd,(a),$len(\0),%x) why the \0 doesn't return its value to identifiers? it returns 2 (the length of "\0") except 4 3. and another question, what is the maximum times that regex can match with //g or a lot of ( )'s ?
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
1. $regml(1).pos
2. It's just the way it works. mirc first evaluates the content of <subtext>, seeing nothing special in \1 (just like it does with every other identifier), then passes the (evaluated) string to the appropriate PCRE function. What you want might be a bit of a pain to implement but is not impossible (and, if I remember what I read correctly, the new version of PCRE would make things easier towards this direction). I would personally like to see <subtext> working in a manner similar to the <command> parameter in $findfile(), ie filling $1- with each captured match and allowing you to pass it to identifiers.
3. I am pretty sure it's no less than 999. What is important to know is that it definitely works with up to ~930 matches, which is about the max number of characters you can have in a mirc string. So any limitation in the number of captures wouldn't show up in mirc anyway.
Last edited by qwerty; 08/07/03 05:28 PM.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
oh, thanks about the first question, i wanted to return the position of the \1 (in $regsub, not $regex and then $regml) like $regsub(abcd,(b),\1.pos,%x) - %x = a2cd
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
$regml() works with $regsub() too. However, what you want to do here is impossible. There is no way to retrieve the position of \N dynamically from within <subtext>.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 169
Vogon poet
|
Vogon poet
Joined: Dec 2002
Posts: 169 |
You can use $replace as a work around. You just need a character or string of characters you know will not exist in the original string.
var %x
!.echo -q $regsub(abcd,(b),$crlf,%x)
%x = $replace(%x,$crlf,$regml(1).pos)
;or use one regex and one regsub.
!.echo -q $regex(myregex,abcd,(b))
!.echo -q $regsub(myregsub,abcd,b,$regml(myregex,1).pos,%x) Not exactly what you want but it should work.
Last edited by Jerk; 08/07/03 07:03 PM.
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
nah.. that's not a good idea. i want to make it with one $regsub. thanks anyway
|
|
|
|
Joined: Feb 2003
Posts: 2,812
Hoopy frood
|
Hoopy frood
Joined: Feb 2003
Posts: 2,812 |
If you are simply looking to do exactly what your example shows, replace 'b' or any character with its relative position in the string, this can easily be done using $bfind and /bset with your string in a &binvar.
As far as getting $regsub to perform miracles, it simply wont happen. $regsub is incapable of dynamic replace strings. Eg, $upper(\1) will not give you an uppercase 'B'. This may be possible to do in PERL, but not with PCRE, and is completely out of Khaled's hands.
- Raccoon
Well. At least I won lunch. Good philosophy, see good in bad, I like!
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
As far as getting $regsub to perform miracles, it simply wont happen.
It's not a miracle he's asking for... Getting $regsub to work like this:
$regsub(abcd,/(.)/g,$upper($1),%a)
is very much possible. If something like this can work in $findfile() why couldn't it in $regsub()? Hell, I could even script this using only $regml() and $regml().pos, if only there was a way to avoid evaluation of the 3rd parameter in scripts (ie in $myregsub(), $3 would have to return "$upper($1)", not the evaluated content of it) without having to escape anything with ! or $+ or $eval(...,0) etc.
I originally thought that $regsub() calls a ready-made PCRE function, so that Khaled had no actual control over it (unless he attempted to mess with the PCRE source himself). However, I was browsing through the PCRE source today and found no function that does any $regsub-related job, so I can only assume that $regsub() is hand-made. If this is the case, it's good news; implementing this feature would be WAY easier (although I insist that it would still be possible even if this wasn't the case).
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: May 2003
Posts: 730
Hoopy frood
|
OP
Hoopy frood
Joined: May 2003
Posts: 730 |
yeah, i have suggested that once that $neval($N) will return the $Nth parameter from the alias without evaluating it
|
|
|
|
|