2017-11-13 2 views
0

"941d3c8a-8d5d-42aa-943e-a07ccaba1629"가 포함 된 항목을 필터링하고 각 필터링 된 항목의 값을 가져 오려고합니다. 첫 번째 필터링 된 항목의 경우 값은 " "이고 두 번째 값은 "ROBO7"입니다.C# : 필터/html-table에서 특정 열의 값을 정규식으로 얻는 방법. 두 문자열 사이의 값 얻기

아래와 같이 C#에서 regex를 사용했지만 올바른 값을 얻을 수없는 것 같습니다. 도움을 주시면 감사하겠습니다.) (업데이트)

Regex regex = new Regex(
     "(<TD[^>]*?>^941d3c8a-8d5d-42aa-943e-a07ccaba1629$<\\/TD>)", 
    RegexOptions.IgnoreCase 
    | RegexOptions.CultureInvariant 
    | RegexOptions.IgnorePatternWhitespace 
    | RegexOptions.Compiled 
    ); 
MatchCollection ms = regex.Matches(InputText); 
int index = 1; 
foreach (Match match in ms) 
{ 
if (match.Groups[2].Value.StartsWith(Search)) 
    return index; 
    index++; 
} 
return 0; 

enter image description here

<TABLE class="mainlayout fixedlayouttable" cellSpacing=0 cellPadding=2 width=1223 summary=* border=0> 
 
<TBODY> 
 
<TR openspan_RowSchemaId="efbd02b8-fb2f-4f1c-8091-2d82e9bd0220"> 
 
<TD width=82 noWrap openspan_CellSchemaId="53174ff2-e55c-472b-ae59-6d430afb3f10"><A onclick="doScanNo('G1S1990706')" href="#">G1S1990706</A> </TD> 
 
<TD width=95 openspan_CellSchemaId="4be80351-39e7-4f8a-be50-9233436a3266">G1:一般支払 </TD> 
 
<TD width=100 openspan_CellSchemaId="6e5e1343-ef24-4e55-b2a6-9d7c422400c8">R1:QRなし </TD> 
 
<TD width=84 noWrap openspan_CellSchemaId="99bb881d-2870-4742-9ebc-689337842cd5">&nbsp; </TD> 
 
<TD width=160 noWrap openspan_CellSchemaId="26265b76-713e-4543-9bd5-334416e8b0df"><SPAN class=nowraptext><BR></SPAN></TD> 
 
<TD width=186 noWrap openspan_CellSchemaId="785a8e77-1803-4123-94d4-f878f372b86d"><SPAN class=nowraptext><BR></SPAN></TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="83fd103d-ee4b-45e8-adb1-7df59fff170c">RobotAgent1 </TD> 
 
<TD class=same width=79 noWrap openspan_CellSchemaId="7016e294-b4f4-433f-8711-d798e0b90cf1">2017/09/20 </TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="6c26eb0d-0195-45b8-a07b-5b0ac26c636d">ROBO7 </TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="a7ebc00f-32ad-4fcf-b991-81983587a91d">&nbsp; </TD> 
 
<TD class=same width=79 noWrap openspan_CellSchemaId="6e9ce592-309b-4288-9e96-09c3f3a4374d">2017/11/07 </TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="941d3c8a-8d5d-42aa-943e-a07ccaba1629">&nbsp; </TD></TR> 
 
<TR openspan_RowSchemaId="efbd02b8-fb2f-4f1c-8091-2d82e9bd0220"> 
 
<TD width=82 noWrap openspan_CellSchemaId="53174ff2-e55c-472b-ae59-6d430afb3f10"><A onclick="doScanNo('G1S1990716')" href="#">G1S1990716</A> </TD> 
 
<TD width=95 openspan_CellSchemaId="4be80351-39e7-4f8a-be50-9233436a3266">G1:一般支払 </TD> 
 
<TD width=100 openspan_CellSchemaId="6e5e1343-ef24-4e55-b2a6-9d7c422400c8">01:スキャン済 </TD> 
 
<TD width=84 noWrap openspan_CellSchemaId="99bb881d-2870-4742-9ebc-689337842cd5">&nbsp; </TD> 
 
<TD width=160 noWrap openspan_CellSchemaId="26265b76-713e-4543-9bd5-334416e8b0df"><SPAN class=nowraptext><BR></SPAN></TD> 
 
<TD width=186 noWrap openspan_CellSchemaId="785a8e77-1803-4123-94d4-f878f372b86d"><SPAN class=nowraptext><BR></SPAN></TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="83fd103d-ee4b-45e8-adb1-7df59fff170c">RobotAgent2</TD> 
 
<TD class=same width=79 noWrap openspan_CellSchemaId="7016e294-b4f4-433f-8711-d798e0b90cf1">2017/09/20 </TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="6c26eb0d-0195-45b8-a07b-5b0ac26c636d">ROBO7 </TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="a7ebc00f-32ad-4fcf-b991-81983587a91d">&nbsp; </TD> 
 
<TD class=same width=79 noWrap openspan_CellSchemaId="6e9ce592-309b-4288-9e96-09c3f3a4374d">2017/11/13 </TD> 
 
<TD width=78 noWrap openspan_CellSchemaId="941d3c8a-8d5d-42aa-943e-a07ccaba1629">ROBO7 </TD></TR> 
 
</TBODY> 
 
</TABLE>

답변

2

당신이 필요한 정규식이

(?<=941d3c8a-8d5d-42aa-943e-a07ccaba1629">)(.*)(?=<\/TD>) 

내가 조금 당신에게 C#을 솔루션을 게시 할 예정입니다

Regex를 테스트해야한다면 here 조건의 유효성을 확인하십시오. 그것은 조건에 따라 두 문자열 사이의 모든 것을 일치시킵니다. 여기

는 간단한 코드 예제입니다 (난 그냥 인쇄하고 있습니다하지만 당신은 당신이 그것으로 원하는대로 할 수있는) oetoni는, 그것은 작동

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.IO; 
using System.Text.RegularExpressions; 

namespace test3 
{ 
    class Program 
    { 

     static void Main(string[] args) 
     { 

      string createText = System.IO.File.ReadAllText(@"C:\PATH_TO_THE FILE_I_USED\data.txt"); 

      Regex regex = new Regex("(?<=941d3c8a-8d5d-42aa-943e-a07ccaba1629\" >)(.*)(?=<\\/ TD >)", 
       RegexOptions.IgnoreCase 
       | RegexOptions.CultureInvariant 
       | RegexOptions.IgnorePatternWhitespace 
       | RegexOptions.Compiled 
       ); 

      MatchCollection ms = regex.Matches(createText); 

      foreach (Match match in ms) 
      { 
       Console.WriteLine(match); 
      } 

      Console.ReadLine(); 
     } 

    } 
} 
+0

감사합니다. :) –

관련 문제