开发者

regexp to get data for some symbol [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 8 years ago.

Improve this question

I'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&#160;1.&#160;&#160;</FONT></B> 
</TD> 
<TD> 


<A name='Y86310103'> 
<DIV style="margin-top: 4pt; font-size: 1pt">&nbsp;</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&#160;1.

Another input example is

<TD WIDTH="9%" VALIGN="top" ALIGN="left"><FONT STYLE="font-family:Times New Roman"    SIZE="2"><B><U>ITEM&nbsp;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&nbsp;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&#160;13.&#160;&#160;
Item&#160;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&#160;1.&#160;&#160;</FONT></B> 
</TD> 
<TD> 
<A name='Y86310103'> 
<DIV style="margin-top: 4pt; font-size: 1pt">&nbsp;</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"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜