regexp to get data for some symbol [closed]
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this questionI'm using
preg_match_all ("#Item(.*?)1\.#si", $file, $matches);
I want to get result like "Item 1." or
Item  1.
But now i got something like "Item 405"
Item 9B.  
Item 13.  
Any suggestion?
Sample input
<TR valign="top">
<TD>
<B><FONT style="font-family: 'Times New Roman', Times">Item 1.  </FONT></B>
</TD>
<TD>
<A name='Y86310103'>
<DIV style="margin-top: 4pt; font-size: 1pt"> </DIV>
<DIV align="left" style="margin-left: 0%; margin-right: 0%; font-size: 10pt; font-family: Arial, Helvetica; color: #000000; background: transparent">
I want to get
Item 1.
Another input example is
<TD WIDTH="9%" VALIGN="top" ALIGN="left"><FONT STYLE="font-family:Times New Roman" SIZE="2"><B><U>ITEM 1.</U></B></FONT></TD>
<TD ALIGN="left" VALIGN="top"><FONT STYLE="font-family:Times New Roman" SIZE="2"><B>
开发者_开发百科I want to get
ITEM 1.
Actually, I want to get the position of "item 1." in the html file. There are other similar entries like "item 1a.", "item 11"
Item 13.  
Item 60l
I don't need those information.
Thank!
Your regular expression matches what you expect (as I understood). See it here online in the regex tester Regexr.
This is a useful tool to develop and test regular expressions, I think it helps you with your problem.
Try this regular expression:
"#Item(&\#160;|\s)1\.#si"
Change "1" to what you really are searching for - perhaps you can tell us more about this.
try:
$file = <<< EOF
<TR valign="top">
<TD>
<B><FONT style="font-family: 'Times New Roman', Times">Item 1.  </FONT></B>
</TD>
<TD>
<A name='Y86310103'>
<DIV style="margin-top: 4pt; font-size: 1pt"> </DIV>
<DIV align="left" style="margin-left: 0%; margin-right: 0%; font-size: 10pt; font-family: Arial, Helvetica; color: #000000; background: transparent">
EOF;
preg_match_all('/(Item)(?:&.*?)?;(\w+)/i', $file, $matches, PREG_PATTERN_ORDER);
$match = $matches[1][0]." ". $matches[2][0];
echo $match; // echo's "Item 9B"
精彩评论