mIRC Home    About    Download    Register    News    Help

Print Thread
#35020 08/07/03 04:41 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
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 ?







#35021 08/07/03 05:26 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
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
#35022 08/07/03 05:43 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
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


#35023 08/07/03 06:38 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
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
#35024 08/07/03 06:45 PM
Joined: Dec 2002
Posts: 169
J
Vogon poet
Offline
Vogon poet
J
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.
Code:
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.
#35025 08/07/03 07:16 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
Joined: May 2003
Posts: 730
nah.. that's not a good idea. i want to make it with one $regsub.
thanks anyway


#35026 08/07/03 07:42 PM
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
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!
#35027 09/07/03 12:07 PM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
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
#35028 09/07/03 12:20 PM
Joined: May 2003
Posts: 730
S
ScatMan Offline OP
Hoopy frood
OP Offline
Hoopy frood
S
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


Link Copied to Clipboard