提取双引号之间的值 [英] Extract the values between the double quotes

查看:85
本文介绍了提取双引号之间的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想只提取双引号内的单词

< script type =" text / javascript"> window.onload = function(){href =" / index?ID = 3071087873023144" ;;}



答案必须是:/ index?ID = 3071087873023144

I want to extract only those words within double quotes
<script type="text/javascript">window.onload = function() {href = "/index?ID=3071087873023144";}

The answer must be: /index?ID=3071087873023144

我是C#的新手,你能帮助我吗?

I'm new to C #, can you help me please?

推荐答案

因为这是HTML我强烈建议您使用工具包来解析HTML而不是尝试进行简单的字符串解析。对于简单的字符串解析,HTML太复杂了。

As this is HTML I strongly recommend that you use a toolkit to parse the HTML rather than trying to do simple string parsing. HTML is too complex for a simple string parse.

但是,给定一个简单的字符串,如attr =" value"您可以使用简单的RE来查找信息。从整个脚本标记中缩小它们最多只会产生问题。同样,使用像HtmlAgilityPack这样的HTML解析器将是最好的路径。

However, given a simple string like attr="value" you can use a simple RE to find the information. Narrowing that down from your entire script tag those is problematic at best. Again, using an HTML parser like HtmlAgilityPack would be the best route.

(?<attribute>\w+)\s*=\s*"(?<value>.*)"

MSDN
有一个如何在正则表达式中使用它的示例。

MSDN has an example of how to use that in a regular expression.

请注意,您的完整脚本标记将不起作用,因为您想要的值已经在属性值中,因此它永远不会看到它。因此,为什么HTML解析器是更好的选择。

Note that your full script tag won't work because the value you want is inside an attribute value already so it'll never see it. Hence why an HTML parser is a better choice.


这篇关于提取双引号之间的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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