如何从C#中的URL查询字符串中提取值? [英] How to extract a value from a URL query string in C#?

查看:80
本文介绍了如何从C#中的URL查询字符串中提取值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

从Uri中获取单个查询参数

我有得到了这样的网址:

I have got a URL like this:

http://somedomain.com/website/webpage.aspx?token=123456&language=English

我的目标是提取123456 query-string参数中只能有一个付款ID。我可以使用哪种正则表达式?我正在使用C#(.NET)。

My goal is to extract 123456 from it. There can only be one payment ID in the query-string parameter. What kind of regular expression can I use? I am using C# (.NET) by the way.

谢谢

推荐答案

token =(\d +)应该可以解决问题

也可以满足aplhas的需要要么执行以下操作:

To cater for aplhas as well you can do either:

token =([[a-zA-Z0-9 + / =] +)即可匹配您期望的字符。这将匹配令牌=,然后捕获与字符类匹配的所有以下字符,即az,AZ,0-9,+,/和=。

token=([a-zA-Z0-9+/=]+) to explicitly match on the characters you expect. This matches "token=" and then captures all following characters that match the character class, that is, a-z, A-Z, 0-9, +, / and =.

token =([[^&#] +)以匹配除您知道的字符以外的任何字符可以完成令牌。这匹配 token =,然后捕获所有字符,直到第一个& 或字符串的末尾

token=([^&#]+) to match any character except for the ones you know can finish the token. This matches "token=" and then captures all characters until the first &, # or the end of the string.

这篇关于如何从C#中的URL查询字符串中提取值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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