douya1061 2015-06-05 20:50
浏览 570

正则表达式匹配新行包含一行一行只包含特定字符

I have a text for a book pages that may have footnotes at the end of the string like the following example:

والخاتِم بكسر التاء اسم فاعل، فكأنه قد جاء آخر الرسل، والخاتَم بفتح التاء اسم آلة، كأنه قد ختمت به الرسالة.
__________

(1) - سورة الأحزاب آية : 43.
(2) - سورة البقرة آية : 157.
(3) - سورة الأنعام آية : 17.
(4) - سورة الكهف آية : 19.

The line that I mean in the sample and the specific characters in this case are Kashidas _ (It is not dash -), in Latin, it called underscore. What I need to get is matching the four lines or any number of lines under that line.

What I have tried let only to match the first line under that line:/_.* *(.*)/gum and this is a demo. The only way to get them all, is to repeat the pattern portion *(.*) n times equals to the number of lines in the footnotes i.e four times, regarding the example case, and this is not a practical solution like this demo

  • 写回答

3条回答 默认 最新

  • doufusi2013 2015-06-05 20:56
    关注

    You can utilize the \G anchor here:

    preg_match_all('~(?:\G(?!^)|_)\R+\K[^
    ]+~', $str, $matches);
    print_r($matches[0]);
    

    eval.in

    评论

报告相同问题?

悬赏问题

  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
  • ¥15 C# datagridview 单元格显示进度及值
  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配