【问题标题】:Non-greedy regex to extract text [duplicate]提取文本的非贪婪正则表达式[重复]
【发布时间】:2020-08-03 10:03:08
【问题描述】:

我正在尝试使用非贪婪正则表达式 (.+)[? 检索此文本的第一部分 Book I\n Psalms 1–41\n Psalm 1\n,但它突出显示了所有内容,任何帮助将不胜感激,谢谢!

Book I\n Psalms 1–41\n Psalm 1\n [1] Blessed is the one\n who does not walk in step with the wicked\n or stand in the way that sinners take\n or sit in the company of mockers,\n [2] but whose delight is in the law of the Lord,\n and who meditates on his law day and night.\n [3] That person is like a tree planted by streams of water,\n which yields its fruit in season\n and whose leaf does not wither—\n whatever they do prospers.\n \n [4] Not so the wicked!\n They are like chaff\n that the wind blows away.\n [5] Therefore the wicked will not stand in the judgment,\n nor sinners in the assembly of the righteous.\n \n [6] For the Lord watches over the way of the righteous,\n but the way of the wicked leads to destruction.\n"

【问题讨论】:

    标签: python-3.x regex


    【解决方案1】:

    我想你正在寻找^(.+?)(?=\[)

    Demo

    【讨论】:

    • @GeraldLim 习惯上赞成并接受解决您问题的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 2016-01-18
    相关资源
    最近更新 更多