请教写以下正则表达式
网页上有一段如下:
<td align= "right "> 证件号码 </td>
<input type= "text " value= "4501051988123123123 " readonly= "readonly " style= "width:86% " class= "textarea ">
请问如何提取那串数字?就是4501051988123123123。
顺便请求各位如何删除字符串的换行符呢?谢谢
------解决方案--------------------楼主最好多给几个例子,一个实例匹配出来的未必通用
string yourStr = ............;
Match m = Regex .Match(yourStr, @ " <input[^> ]*?value= " "(? <value> [^ " "]*?) " "[^> ]*?> ", RegexOptions.IgnoreCase);
if(m.Success)
{
string resultStr = m.Groups[ "value "].Value;
}
删除字符串的换行符用Replace就行了,例如
resultStr = resultStr.Replace( "\r ", " ");
resultStr = resultStr.Replace( "\n ", " ");
------解决方案--------------------如果只想提取证件号码那串数字,可以这样
string yourStr = ............;
string resultStr = string.Empty;
Match m = Regex.Match(yourStr, @ "证件号码 </td> \s* <input[^> ]*?value= " "(? <value> [^ " "]*?) " "[^> ]*?> ", RegexOptions.IgnoreCase);
if (m.Success)
{
resultStr = m.Groups[ "value "].Value;
}
如果想具有灵活性,能提示任意想要的数字串,可以这样,其中exp可为“客户标识”,“证件号码”,“客户编号”等
string exp = textBox1.Text;
string resultStr = string.Empty;
Match m = Regex.Match(yourStr, exp+@ " </td> \s* <input[^> ]*?value= " "(? <value> [^ " "]*?) " "[^> ]*?> ", RegexOptions.IgnoreCase);
if (m.Success)
{
resultStr = m.Groups[ "value "].Value;
}
如果都想取出来,可以用MatchCollection方式,一次性全取出来