|
|
|
Joined: Mar 2004
Posts: 21
Ameglian cow
|
OP
Ameglian cow
Joined: Mar 2004
Posts: 21 |
Hello, I've 3 little issues with Regex (I'm not sure the both first are resolvable, but it would be good if yes ) 1°) $regsub(,,$alias(\1),)
; Is it possible to send backreference to be processed in an alias right away in the $regsub ? for example:
var %x, %i = $regsub(blabla,/(a)/g,$upper(\1),%x) | echo -a %x ...
; ... would give blAblA ! (perhaps a good feature for a next version ? if nobody has already asked for)
2°) $regex(,[$null])
var %test = $null
var %string = bla;0;bla
var %pat = ;(0|[ $+ %test $+ ]);
$regex(%string,%pat)
With this variables, $regex doesn't work (* error message) because pattern corresponds to (0|[]) if %test is $null, whereas %string has a 0 between the both ;; Does a mean exits so that the $regex works ? In the way where 0 corresponds to the (re)search , $regex wouldn't need to check if the second condition 'OR' (|[]) is good or not.. because the first is valid ! It's the [] without value in which is the problem in fact.. possible to bypass this issue ?! (However, %test could have a value in certain case, and %string don't have always 0 but the value of %test, so, don't say me "Remove your [ $+ %test $+ ] it is useless :tongue:" (except if it is the only solution)) 3°) $regexI have trouble making a 'search profil' to check the presence of a character in a string as:
var %test = b
var %string = gni;abc;gni
var %pat = gni;(.?.?[ $+ %test $+ ].?.?);gni
$regex(%string,%pat)
The purpose beiing to know if %test is in ;abc;, however %test can take a, b, or c value and %string can contain ;abc; or just ;ab; or ;ac; or ;b; etc... The example i've given works fine, but there is perhaps easier ? :] Thanks (& sorry for my english)
-Be cool with my English- irc.EpiKnet.org:#scripts
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
1°) PHP, Javascript and possibly other languages like Perl allow you to do that, but mIRC doesn't. It would be a great feature suggestion 2°) What you get is a pattern compilation error that always makes $regex return 0. PCRE (the regex engine) just can't handle [], it seems.
|
|
|
|
Joined: Dec 2002
Posts: 2,962
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 2,962 |
1) No it can't be done currently. Of course you can take the long route and use $regml(), but depending on the exact pattern it can get very complicated sometimes. This is something I'd very much like to see.
2) Change: var %pat = ;(0|[ $+ %test $+ ]); to var %pat = ;(0 $+ $iif(%test != $null, |[ $+ %test $+ ]) $+ ); I haven't tested that but it should work.
Spelling mistakes, grammatical errors, and stupid comments are intentional.
|
|
|
|
Joined: Mar 2004
Posts: 21
Ameglian cow
|
OP
Ameglian cow
Joined: Mar 2004
Posts: 21 |
Thanks a lot for yours both answers In fact, the examples i've given are just extracts of more complicated $regsub & $regex pattern (for the 1st point, i will search another solution that $regml() ), but for the 2nd issue, i haven't thought about an $iif() condition, thx for the idea, i will try that
-Be cool with my English- irc.EpiKnet.org:#scripts
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Hi, regarding your first suggestion, yes, I would love to see that enabled as well, it would be really handy. Of course I don't know in what context you want to make use of that feature (probably a lot more advanced), but to give an example of an ugly hack to get the required result:
alias test {
var %x, %i = $regsub($1-,/(a)/g,$cr \$+ \$upper(\1) \$+ $cr,%x)
echo -a $remove($(%x,2),$cr)
}
/test blablabla and haha -> blAblAblA And hAhA Of course one could do $replace($1-,a,A) but that's besides the point. Greets
Last edited by FiberOPtics; 29/05/04 11:56 AM.
Gone.
|
|
|
|
|
|
|
|