YQtaku

正则苦逼就救……

  •  
  •   YQtaku · Dec 27, 2012 · 3250 views
    This topic created in 5075 days ago, the information mentioned may be changed or developed.
    jekyll是通过正则将

    ---
    layout: post
    ---
    #content
    some words.....

    将文章内容读出来吗?(即读取markdown文件,将首个匹配到的`---任何字符---`去掉?
    请问这个正则要怎么写囧,想了半天没想到……Orz
    7 replies  •  1970-01-01 08:00:00 +08:00
    catfan
    catfan
    PRO
    Dec 27, 2012
    1
    /[\-]+\s+.*\s+[\-]+/i
    Catstyle
    Catstyle
    Dec 27, 2012
    2
    @catfan
    楼主到底是要把`---任何字符---`去掉,还是将文章内容(some words.....)读出来?
    YQtaku
    YQtaku
    OP
    Dec 27, 2012
    3
    @Catstyle 意思都差不多吧?读取整个文件
    - 將首个`---任何字符---`替换成空
    - 或者匹配首个`---任何字符---`以外的内容读出来
    for4
    for4
    Dec 27, 2012
    4
    ---.*?---
    用单行懒惰模式
    YQtaku
    YQtaku
    OP
    Dec 27, 2012
    5
    @catfan 谢谢喵大~ It works~

    @for4 这个没有效果=。=

    preg_replace('/[\-]+\s+.*\s+[\-]+/i', '', "---\nkey:value\n---\n#content\nsome words\n---test"); // it works.

    preg_replace('/---.*?---/', '', "---\nkey:value\n---\n#content\nsome words\n---test"); // it doesnot work.

    看来要正式学一下正则了QAQ
    Catstyle
    Catstyle
    Dec 27, 2012
    6
    @for4
    人家是多行的

    @YQtaku
    好吧, 我有强迫症,去掉和读取是不一样的...
    for4那个也可以,不过要在后面加上s就可以开启多行模式了
    即/---.*?---/s
    Catstyle
    Catstyle
    Dec 27, 2012
    7
    @for4
    @YQtaku
    不好意思,表达有误,是DOTALL模式,即‘.’也可匹配换行符
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2765 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 04:25 · PVG 12:25 · LAX 20:25 · JFK 23:25
    ♥ Do have faith in what you're doing.