正则表达式< span>标签 [英] regex for <span> Tag

查看:113
本文介绍了正则表达式< span>标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个跳过产品ID的正则表达式



I want to write a regular expression that skip product id

<span class="Price" id="product-id-453">34.65</span>




<span class="Price" id="product-id-553">343.65</span>







Regex regex = new Regex("<span class="\Price\" id="553">(.*)</span>");





我遇到了问题在span标记的id部分中



I am having problem in id part of span tag

推荐答案

问题是ID553的硬编码,它将为id453失效。您也可以通过规范Id部分来忽略它。试试这个



The problem is the hardcoding of the ID "553" which will faild for id "453". You can ignore it by regularizing Id part as well. Try this

<span class="Price" id="\d+">(.*)<\/span>


您可以尝试

You might try
Regex regex = new Regex(@"<span class=""Price"" id=""\d+"">(.*)</span>");


除了_Asif_所说的,更改代码以及:

in addition to what _Asif_ says, change you code as well:
Regex regex = new Regex("<span class="\Price\" id="553">(.*)</span>");

反斜杠位置错误,无法编译:

Has backslashes in the wrong place, and won't compile:

Regex regex = new Regex("<span class=\"Price\" id=\"\d{3}\">(.*)</span>");







我们的id是字母数字产品-id-543

如果您要使用正则表达式,那么您需要能够对它们进行至少基本的更改!




"f our id is alpha-numeric product-id-543"
If you are going to use regexes, then you need to be able to make at least basic changes to them!

Regex regex = new Regex("<span class=\"Price\" id=\"\.+?\">(.*)</span>");

应该这样做。



获取 Expresso [ ^ ] - 这是free,它检查并生成正则表达式。

Should do it.

Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.


这篇关于正则表达式&lt; span&gt;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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