使用正则表达式或ToDicitionary提取网址 [英] fetching url using regex or ToDicitionary

查看:84
本文介绍了使用正则表达式或ToDicitionary提取网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取

"oauth_verifier=RN9vtxDFfozW51CSTuls0J4C&oauth_token=4%2F3uYq_3vYUSjXaFXtS74B_laW2V4d"

RN9vtxDFfozW51CSTuls0J4C

RN9vtxDFfozW51CSTuls0J4C

4%2F3uYq_3vYUSjXaFXtS74B_laW2V4d

4%2F3uYq_3vYUSjXaFXtS74B_laW2V4d

从上面的字符串开始吗?

from the string above?

1)使用正则表达式

2)使用ToDictionary(选择器)

2) Using ToDictionary(selector)

推荐答案

正则表达式:

使用正面的眼光:

用于获取oauth_verifier值的正则表达式模式:

Regex pattern for fetching oauth_verifier's value:

(?<=oauth_verifier=).+(?=&)

用于获取oauth_token值的正则表达式模式:

Regex pattern for fetching oauth_token's value:

(?<=oauth_token=).+

例如:

string input = "oauth_verifier=RN9vtxDFfozW51CSTuls0J4C&oauth_token=4%2F3uYq_3vYUSjXaFXtS74B_laW2V4d";
string oauth_verifier = Regex.Match(input, "(?<=oauth_verifier=).+(?=&)").Value;
string oauth_token = Regex.Match(input, "(?<=oauth_token=).+").Value;

ToDictionary

var dic = input.Split('&').ToDictionary( s => s.Remove(s.IndexOf('=')), s => s.Substring(s.IndexOf('=') + 1));

这篇关于使用正则表达式或ToDicitionary提取网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆