Home  >  Q&A  >  body text

Regular Expressions - Ask a question about regular expression replacement in nginx

I plan to use nginx's subs_filter to replace certain links or strings, but nginx's regular rules seem to be a little different from those of python and the like. . Here are the tried matches

location / {
   #目的是将https://*.wikipedia.org替换成http://wiki.example.org

    subs_filter .wikipedia.org .wiki.example.org;#这个只能替换成https://wiki.example.org
 
 #也尝试过 subs_filter https://zh.wikipedia.org http://zh.wiki.example.org 但不行,会变成https://zhhttp://example.org       
}

Can you please elaborate? grateful

某草草某草草2714 days ago841

reply all(1)I'll reply

  • 我想大声告诉你

    我想大声告诉你2017-05-16 17:11:29

    subs_filter https://(.*).wikipedia.org http://wiki.example.org ir;
    i表示忽略大小写
    r means the preceding one is regular

    reply
    0
  • Cancelreply