谁能告诉我这个对象的正则表达式是“xauthtoken”?

时间:2016-11-08 07:18:40

标签: javascript html regex

<form method="post" action="./ServiceUserHomePage.aspx?UserId=432795&amp;Username=int_jasimp&amp;SessionKey=E29A0DE7-3048-4C29-93B2-08B5FFF8EF23&amp;xauthtoken=eYa9GR3ghZGwIG46vPsyUhs61ZhT9dxrZLyYTZroSFOaaTo0KKP2yYbQbQomkbGzSFHJ8guzRF+45S%2fxgWdpDrR9zo+0DN0NZAGn1Jq91zUAj8s4UAi3JwfhMP5SKQsyPZR5FRZ7nw2eErO1+6nKDIFf%2f7Phlk2fRxJUPdg+2Tt2lusyZQBpBjMo8MxzhnOd&amp;xauthsrc=UserManagement&amp;xauthdes=EventManagementSystem" id="Form2" autocomplete="off">

xauthtoken值应如下所示:

xauthtoken=eYa9GR3ghZGwIG46vPsyUhs61ZhT9dxrZLyYTZroSFOaaTo0KKP2yYbQbQomkbGzSFHJ8guzRF+45S%2fxgWdpDrR9zo+0DN0NZAGn1Jq91zUAj8s4UAi3JwfhMP5SKQsyPZR5FRZ7nw2eErO1+6nKDIFf%2f7Phlk2fRxJUPdg+2Tt2lusyZQBpBjMo8MxzhnOd

我的正则表达式是:

xauthtoken.*?&

......结果如下:

xauthtoken=eYa9GR3ghZGwIG46vPsyUhs61ZhT9dxrZLyYTZroSFOaaTo0KKP2yYbQbQomkbGzSFHJ8guzRF+45S%2fxgWdpDrR9zo+0DN0NZAGn1Jq91zUAj8s4UAi3JwfhMP5SKQsyPZR5FRZ7nw2eErO1+6nKDIFf%2f7Phlk2fRxJUPdg+2Tt2lusyZQBpBjMo8MxzhnOd&

如果排除&符号,则字符串以Od结尾。

2 个答案:

答案 0 :(得分:1)

let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager() fbLoginManager.logOut() fbLoginManager.logInWithReadPermissions(["email", "user_friends"], fromViewController: self) { (result, error) -> Void in if (error == nil){ let fbloginresult : FBSDKLoginManagerLoginResult = result if(fbloginresult.grantedPermissions.contains("email")) { self.getFBUserData() } } else { print(error.description) } } 正则表达式模式匹配xauthtoken.*?&,然后匹配尽可能少的任何0 +字符,直到第一个xauthtoken&本身。

为了避免匹配&但是在它之前抓取所有字符,您需要使用否定字符类 &

[^&]

xauthtoken[^&]* 之后的=。请参阅regex demo

答案 1 :(得分:1)

试试这个:

xauthtoken.*?(?=&)

演示:https://regex101.com/r/GM3ID6/1