开发者

Preg match won't match, can't figure out why

I am using RegEx Helper website (http://regexpal.com/), and

ENTER.+Security

is matching the following:

ENTER Open-Source Intelligence Team LSU Center for Animal Health, Food Safety, and Bio-Security

However, PHP will not preg_match it, and I cannot figure it out, I have been trying for a couple of hours now, and I feel really stupid that I can't get this little piece to match.

Is it apparent to anybody why? I have tried all kinds of combinations but, the most I can get it to match it ENTER. This is especially frustrating because this is my shortest and simplest RegEx by far, but it just will not match.

Code:

$title = '/(ENTER.+Security)/';


$file = shell_exec('pdf2txt.py docs/April.pdf');
preg_match_all($title, $file, $m);

print_r($m[0]);

When I remove the preg_match part, and I just print the $file, there 开发者_JAVA百科are dozens of visual matches, but it just won't match it programatically.

All I see is this:

Array ( ) 

But the text it should be matching is here:

... /March/17031101.asp (accessed April 4, 2011). World Health Organization. State Food and Drug Administration Gets WHO Approval for Vaccine Regulatory System. March 1, 2011. http://www.wpro.who.int/china/media_centre/press_releases/PR_20110301.htm (accessed April 4, 2011). ENTER Open-Source Intelligence Team LSU Center for Animal Health, Food Safety, and Bio-Security Special Interest Intelligence Report - Alert South Korea – Labeling Issues in Wheat Flour Mix Product...


Try accounting for multiple lines. There's a good chance when you are pasting it into that site that it's removing any line breaks.

preg_match('/ENTER.+Security/m',$str) //note the /m

The forward slash in the example is the delimeter. The following m tells it to match over multiple lines.


Without seeing code it's tough to know for sure what's going on, but my guess is that you're not delimiting your expression correctly. Try this:

preg_match('#ENTER.+Security#', $str);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜