Sign in to follow this  
Followers 0
ActualAkshay

Help with simple parsing

7 posts in this topic

#1 ·  Posted (edited)

oauth_token=<request-token>&oauth_token_secret=<request-token-secret>

best way to parse out <request-token> and <request-token-secret> from above response line? o:)

Edited by ActualAkshay

Share this post


Link to post
Share on other sites



Example
#include <Array.au3>

$String = "oauth_token=<request-token>&oauth_token_secret=<request-token-secret>"
$aRet = StringRegExp( $String, "<.*?>", 3 )

_ArrayDisplay( $aRet )

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Example

#include <Array.au3>

$String = "oauth_token=<request-token>&oauth_token_secret=<request-token-secret>"
$aRet = StringRegExp( $String, "<.*?>", 3 )

_ArrayDisplay( $aRet )

<request-token> and <request-token-secret> will be some random encoded string in the response code, check out the example below

oauth_token=dsfxy2hy32fh4382&oauth_token_secret=h32jbds89hjlaklsl

OR

oauth_token_secret=h32jbds89hjlaklsl&oauth_token=dsfxy2hy32fh4382

i want to parse them out in variables

$oauth_token = "dsfxy2hy32fh4382"
$oauth_token_secret = "h32jbds89hjlaklsl"
Edited by ActualAkshay

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here we go

#include <Array.au3>

$String = "oauth_token_secret=h32jbds89hjlaklsl&oauth_token=dsfxy2hy32fh4382"
$aRet = StringRegExp( $String, "(?:auth_token(?:_secret)?=)([^&]+)", 3 )
_ArrayDisplay( $aRet )

$oauth_token = $aRet[1]
$oauth_token_secret = $aRet[0]

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

If you want to retrieve both the tokens distinctly this would help

The previous script would only retrieve the values, without any priority of positions

Try this Example

$String = "oauth_token_secret=h32jbds89hjlaklsl&oauth_token=dsfxy2hy32fh4382"

$oauth_token = StringRegExpReplace( $String, "(?si)(.*?)(oauth_token=)([^&]+)(.*)", "\3" )
$oauth_token_secret = StringRegExpReplace( $String, "(?si)(.*?)(oauth_token_secret=)([^&]+)(.*)", "\3" )

MsgBox( 0, 0, StringFormat( "token: %s\ntoken_secret: %s", $oauth_token, $oauth_token_secret ) )
Regards :) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites

Here we go

#include <Array.au3>

$String = "oauth_token_secret=h32jbds89hjlaklsl&oauth_token=dsfxy2hy32fh4382"
$aRet = StringRegExp( $String, "(?:auth_token(?:_secret)?=)([^&]+)", 3 )
_ArrayDisplay( $aRet )

$oauth_token = $aRet[1]
$oauth_token_secret = $aRet[0]

If input string is 'oauth_token=dsfxy2hy32fh4382&oauth_token_secret=h32jbds89hjlaklsl'

then 1st element will be

oauth_token

and 2nd

element will be oauth_token_secret

If input string is 'oauth_token_secret=h32jbds89hjlaklsl&oauth_token=dsfxy2hy32fh4382'

then 2nd element will be oauth_token

and 1st element will be oauth_token_secret

what is the best and simplest way to make sure that variable have correct info no matter whats the order of token and token secret in the string is?

Share this post


Link to post
Share on other sites

If you want to retrieve both the tokens distinctly this would help

The previous script would only retrieve the values, without any priority of positions

Try this Example

$String = "oauth_token_secret=h32jbds89hjlaklsl&oauth_token=dsfxy2hy32fh4382"

$oauth_token = StringRegExpReplace( $String, "(?si)(.*?)(oauth_token=)([^&]+)(.*)", "\3" )
$oauth_token_secret = StringRegExpReplace( $String, "(?si)(.*?)(oauth_token_secret=)([^&]+)(.*)", "\3" )

MsgBox( 0, 0, StringFormat( "token: %s\ntoken_secret: %s", $oauth_token, $oauth_token_secret ) )
Regards :)

Oh thanks a lot, thats what I needed, you are GENIUS!!

Regards from India, to India :P

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0