我似乎無法得到這是什麼表情打算提取手柄:PHP正則表達式的幫助
preg_match("/^(?:[\s\*]*[email protected]([^\*\/]+?)\s(.+))/",$line,$match);
$線是從一個文本文件中的線,而$匹配是一個數組
我似乎無法得到這是什麼表情打算提取手柄:PHP正則表達式的幫助
preg_match("/^(?:[\s\*]*[email protected]([^\*\/]+?)\s(.+))/",$line,$match);
$線是從一個文本文件中的線,而$匹配是一個數組
這裏有一個解釋:
^ # match the beginning of the input
(?: # start non-capture group 1
[\s*]*? # match any character from the set {'0x09'..'0x0D', '0x20', '*'} and repeat it zero or more times, reluctantly
@ # match the character '@'
( # start capture group 1
[^*/]+? # match any character from the set {'0x00'..')', '+'..'.', '0'..'ÿ'} and repeat it one or more times, reluctantly
) # end capture group 1
\s # match a whitespace character: [ \t\n\x0B\f\r]
( # start capture group 2
.+ # match any character except line breaks and repeat it one or more times
) # end capture group 2
) # end capture group 1
的示例串的正則表達式將匹配是這樣的:* * *@abc asd
編輯:
我已經發布了用於生成上面的解釋解析器的測試版。它可以在這裏下載:http://big-o.nl/apps/pcreparser/pcre/PCREParser.html
這將匹配形式的字符串
** * ***@anything_that_is_not_an_asterisk_nor_a_slash anything else
$match[1]
包含"anything_that_is_not_an_asterisk_nor_a_slash"
第一空間之前,$match[2]
包含" anything else"
。
這是一個很好的純英文解釋。我得到正則表達式的代碼實際上是試圖提取這種類型的字符串,但是因爲它在$ match [2] – KalenGi 2010-01-18 16:39:28
@讓我覺得該模式試圖捕獲電子郵件的元素... 作爲ROT總是記錄正則表達式。
中選擇CRLF而造成混亂,我一開始也這麼想,但它匹配得多,更多。見Kenny和我的答案。 – 2010-01-18 16:31:52
<[email protected]用戶名>,我認爲其含義實際上取決於輸入/上下文,線條是什麼樣子的? – 2010-01-18 16:34:20
可能試圖捕捉註釋塊這樣的(不包括第一次和最後一行)的行:
/**
* @param $arg1 etc...
* @return bool etc...
*/
這非常類似於源文本。我想知道的是它試圖以一步一步的方式來挑選,以便我可以看到它是怎麼搞的。 – KalenGi 2010-01-18 16:48:01
你有什麼是$行的內容有任何想法? – 2010-01-18 16:35:34
fireeyedboy拿到了文件中的文本結構右: /** * @class的TestClass * * @version 1.0 * @package TestTool * */ – KalenGi 2010-01-18 16:51:28