【问题标题】:Regular Expression in Varnish? What does this regex matches?Varnish中的正则表达式?这个正则表达式匹配什么?
【发布时间】:2013-04-19 19:09:47
【问题描述】:

我在我的日志中看到了一个清除请求,其格式为
req.url ~ "^(.*)(?<!\\d{1})534328(?!\\d{1})"。我不确定正则表达式完全匹配什么。我知道清漆使用 POSIX 正则表达式。我正在尝试为正则表达式 ^(.*)(?<!\\d{1})534328(?!\\d{1}) 生成示例匹配,但无法找到可以帮助我的工具。

编辑:对不起,我根据changelog here.弄错了The regular expression engine is now PCRE instead of POSIX regular expressions.

【问题讨论】:

  • 如果 Varnish 确实使用 POSIX 正则表达式,那么这个正则表达式将不起作用,因为 POSIX 正则表达式不支持环视断言。
  • 对不起,我编辑了这个问题。

标签: regex varnish


【解决方案1】:

它匹配534328 既没有数字也没有数字。

^            # line beginning
(.*)         # any character repeated any number of times, including 0
(?<!\d{1})   # negative look-behind assertion: single digit
534328       # literal 534328       
(?!\d{1})    # negative look-ahead assertion: single digit

  "whatever 534328"      ←  match
  "wharrgarbl 1534328"   ←  no match
  "any chars  5343289"   ←  no match
  "hello world a534328b" ←  match

【讨论】:

  • 不需要冒号,但会匹配行尾的 534328 吗?
  • 嗯?这些只是表格中的示例。好的,我会重新格式化它。
  • 谢谢。是否有在线工具,或者我可以测试的 C/c++/ 或 php 函数?
  • 不确定哪个在线工具最好,但在 PHP 中,preg_match 函数及其朋友使用 PCRE。
  • 我没有尝试过 PHP 版本,但其他一些版本在这里工作得很好:regexplanet.com/advanced/php/index.html
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-08-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多