获取2个字符之间的字符串 [英] get string between 2 characters

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

问题描述

<div class="image-wrapper">
<img src="http://img6a.flixcart.com/image/book/2/9/9/essential-english-grammar-murphy-400x400-imadbjz55tzgmnr9.jpeg" onload="img_onload(this);"  önerror="img_onerror(this);" data-pid="9788175960299" data-imagesize="pp_main_new" data-error-url="http://img1a.flixcart.com/img/book.jpg" class="small_image product-image imageZoom " alt="Buy Essential English Grammar: A Self-Study Reference and Practice Book for Elementary Students of English with Answers 2nd Edition: Book" title="Essential English Grammar: A Self-Study Reference and Practice Book for Elementary Students of English with Answers 2nd Edition: Book" id="visible-image-small" rel="IMADBJZ55TZGMNR9" data-zoom-src="">
</div>





i只想采取:

http://img6a.flixcart.com/image/book/2/9/9/essential-english-grammar-murphy-400x400-imadbjz55tzgmnr9.jpeg



来自字符串



i有



i want to take only:
http://img6a.flixcart.com/image/book/2/9/9/essential-english-grammar-murphy-400x400-imadbjz55tzgmnr9.jpeg

from the string

i have

string get_image_path = @"<div class='image-wrapper'><img src=(.*?) önload=""img_onload(this)""";
            Regex myRegex = new Regex(get_image_path, RegexOptions.Singleline);
            string image_path = myRegex.Match(result).Groups[1].Value;
            return image_path;





但我没有获得价值我将无效

帮助我

谢谢



but i am not getting value i am getting null
help me
thanks

推荐答案

好吧,我并不感到惊讶 - 你的正则表达式与您的输入不符...

您的班级分隔符不同 - 双引号和单引号不是同一个字符; onload与önload不同;在img_onload(this);的末尾有一个分号而不是在双引号之后,等等。



说真的,我不会用正则表达式来解析HTML:这是一个愚蠢的想法。相反,尝试使用HTML阅读器,它将输入作为HTML处理,并以非常友好和可靠的方式提供线条,属性等。



快速谷歌会在这里找到你的负载: https://www.google.co.uk/search?q=HTML+reader+codeproject&oq=HTML+reader+codeproject& ; aqs = chrome..69i57j0l5.6613j0j7& sourceid = chrome& espv = 210& es_sm = 93& ie = UTF-8 [ ^ ]
Well, I'm not surprised - your regex doesn't match your input...
Your class delimiters are not the same - double quote and single quote are not the same character; "onload" is not the same as "önload"; there is a semicolon at the end of "img_onload(this);" instead of after the double quote, and so forth.

Seriously, I wouldn't parse HTML with a regex: it's a silly idea. Instead try using a HTML reader which will process the input as HTML and provide lines, attributes, and so forth in a much mopre friendly and reliable way.

A quick google will find you loads of them here: https://www.google.co.uk/search?q=HTML+reader+codeproject&oq=HTML+reader+codeproject&aqs=chrome..69i57j0l5.6613j0j7&sourceid=chrome&espv=210&es_sm=93&ie=UTF-8[^]


您也可以使用jQuery。例如,你可以使用代码片段来检查它:



You can go for jQuery also. For example you can check it using the code snippet:

alert(


(< span class =code-string> #visible-image-small)。attr( src));
("#visible-image-small").attr("src"));


这篇关于获取2个字符之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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