mIRC Home    About    Download    Register    News    Help

Print Thread
Filtering URL info? #260323 29/03/17 07:26 PM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
I basically need just the access token for this, looking to make things a bit easier.

Code:
http://localhost/#access_token=THIS_IS_WHAT_I_NEED&scope=channel_read+channel_editor+channel_subscriptions+channel_check_subscription


Is it possible to remove "http://localhost/#access_token=" and "&scope=channel_read+channel_editor+channel_subscriptions+channel_check_subscription" from this when someone does something like

!token http://localhost/#access_token=THIS_IS_W...ck_subscription

that way when they do the !token it'll write just their token to the ini file I have?

EDIT:

So... Yet again, not doing enough searching of the right stuff... If you want something like this use $remove... Sorry.

Code:
 $remove($2-,http://localhost/#access_token=,&scope=channel_read+channel_editor+channel_subscriptions+channel_check_subscription) 



Last edited by Bramzee; 29/03/17 07:52 PM.
Re: Filtering URL info? [Re: Bramzee] #260324 29/03/17 11:16 PM
Joined: Feb 2003
Posts: 2,662
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,662
Code:
var %text = http://localhost/#access_token=THIS_IS_WHAT_I_NEED&scope=channel_read+channel_editor+channel_subscriptions+channel_check_subscription
if ($regex(%text,/access_token=([^&]+)/)) {
  var %token = $regml(1)
}


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: Filtering URL info? [Re: Raccoon] #260325 30/03/17 01:32 AM
Joined: Apr 2014
Posts: 170
Bramzee Offline OP
Vogon poet
OP Offline
Vogon poet
Joined: Apr 2014
Posts: 170
is this easier on my pc/mIRC than the $remove??

Re: Filtering URL info? [Re: Bramzee] #260326 30/03/17 09:06 AM
Joined: Feb 2003
Posts: 2,662
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,662
Is it a grinding operation? No. Regular expressions are fast, and the logic used in the example I gave you might actually use fewer CPU cycles than the logic used in your very lengthy $remove(), byte for byte comparison.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Re: Filtering URL info? [Re: Raccoon] #260331 30/03/17 12:01 PM
Joined: Jul 2006
Posts: 3,576
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,576
Regular expressions are not fast, they are anything you want but fast, especially the engines nowadays, including PCRE, which are not 'regular' anymore.
Again it's important, regular expression are not fast, never, you can't say that; it may be that you meant here it would be faster than the $remove, but doubt it.


Looking for a good help channel about mIRC? Check #mircscripting @ irc.swiftirc.net
Re: Filtering URL info? [Re: Wims] #260339 30/03/17 05:14 PM
Joined: Feb 2003
Posts: 2,662
Raccoon Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,662
Ouims, you are being pedantic again. It's not pretty.

For this user's purposes, there should be no noticeable or even practical loss of PC performance, while the user gains the flexibility of support for dynamically changing input.

In conducting performance speed tests (for a script, lol), on an 8 year old mid-grade Dell Optiplex, I conclude that the $remove and the $regex methods both execute in less than 1/10,000th of a second, with the $regex method being relatively slower but negligibly so. This also in part to requiring two lines of code for regex; one for the $regex() and one for the $regml(). I was still able to iterate 15,000 times without it taking one full second to complete.

Code:
regexspeedtest {
  var %text = http://localhost/#access_token=THIS_IS_WHAT_I_NEED&scope=channel_read+channel_editor+channel_subscriptions+channel_check_subscription
  var %i = 1, %ticks = $ticks
  WHILE (%i <= 10000) {
    inc %i
    var %token = $remove(%text,http://localhost/#access_token=,&scope=channel_read+channel_editor+channel_subscriptions+channel_check_subscription)
    noop $regex(%text,/access_token=([^&]+)/)
    var %token = $regml(1)
  }
  echo -a $calc($ticks - %ticks) ms, %token
}


By alternately removing the lines of code not being tested, my repeatable speed results were such.

$remove = 488 ms @ 10,000 iterations
$regex = 691 ms @ 10,000 iterations
control = 213 ms @ 10,000 iterations

Adjusted for control, $remove took 275 ms, and $regex took 478 ms. Faster than it took to write this.


Well. At least I won lunch.
Good philosophy, see good in bad, I like!