Preg匹配所有与初始行不匹配的文本

时间:2016-04-12 14:16:49

标签: php preg-match-all

所以我正在开发一个PHP应用程序,用户可以使用关键字存储文本,即关键字“Br”文本“Back bone polished”。对于该特定部分,用户将能够编辑它们存储在数据库中的所有文本。这些信息将在标准文本区域内显示如下:

文字区

<textarea rows="15" cols="20" id="inputMulti" wrap="hard" name="inputMulti">

文本区域内的实际文本

na  "No acute cardiopulmonary abnormality. "

!   "Test Bed - Chrome on MacBook Pro.

1. Font is not Courier.
2. Compiler is not working.
3. Buttons are not high-lighting.
4. Edit and Delete buttons not working in Reports.
5. multiple codes "entered" are inappropriately separated by commas, that are carried over from box 1. 
6. On Show list page, instead of view, we can just simplify and go straight to edit.
7. Once you Delete a code from the Code View page, you get an Page Not Found error.
8. MRI Code Typer is not linked to Home; and actually, Home doesn't need to be there, the MRI Code Typer 2 would be fine.
9. Box 2 doesn't lengthen as expected; once text field is expanded, "only" a part of it is seen, until additional typing is performed, only then does Box 2 expand properly."

0c  "Comparison: unavailable . 

FINDINGS:

$$$L,PL,H,B,f0$

IMPRESSION:
$na$
$$"

L   """""There is no discernible mass or lobar pneumonia. "

f0  "No displaced fracture or acute osseous deformity is seen. "

键位于\ t“之前,相应键的文本位于相应的”“内。

现在我要做的就是将各种东西拉到各自的“”之间。 delima是我不能爆炸“因为”“里面的文字可能包含”,这当然会引起问题。

我设法创建了一个preg_match_all表达式,如下所示。

preg_match_all("/[\t][\"^\a](...*)[\"$\z\n\r]/", $input_lines, $output_array);

Preg Match All的输出

array(
0=> "No acute cardiopulmonary abnormality. "
1=> "Test Bed - Chrome on MacBook Pro.
2=> "Comparison: unavailable . 
3=> """""There is no discernible mass or lobar pneumonia. "
4=> "No displaced fracture or acute osseous deformity is seen. "
)

现在这部分工作,因为它抓取每一行的正确文本,但如果你注意到键2,它不包括“”之间的所有文本,因为它在初始匹配后停止,尽管它应该继续直到它到达比赛的结尾,扩大了几条线。

我试图添加s修饰符,但只将所有匹配放在一个未被行分解的数组中。我也尝试了m修饰符,但似乎根本没有改变任何东西。

1 个答案:

答案 0 :(得分:3)

经过几次测试后我觉得我明白了。试试这个模式:

preg_match_all("/\t\"([^\t]*)\"/", $input_lines, $output_array);

使模式匹配除标签之外的所有内容(标签是关键字和文本之间的分隔符)。在多行文本的情况下,这将包括匹配中的换行符。为此,我考虑到文本中间没有标签,即标签仅用于将关键字与其对应的文本分开。