【问题标题】:Ruby Regexp ( Match string inside brackets )Ruby Regexp(匹配括号内的字符串)
【发布时间】:2015-03-06 23:50:58
【问题描述】:

有谁知道如何匹配不在括号中的字符串 [^...] 例如:我想匹配所有内容,直到最后一个“空格和 [”在一起

This is my regex: (?<cookie>[^[( \[)]]*)
This is my string: country=US; lngCode=en; ga_cid=a*d%5d]7b7[6-4369-ad62-9 [
This is my result: country=US;
This is what i would like to have: country=US; lngCode=en; ga_cid=a*d%5d]7b7[6-4369-ad62-9

我的正则表达式匹配第一个空格而不是空格和 [ 一起

非常感谢!

【问题讨论】:

    标签: regex logging apache2 fluentd


    【解决方案1】:

    您可以使用/^(?&lt;cookie&gt;.*) \[$/。它将匹配并捕获从一行的开头到该字符串末尾的最终“空格+文字'['”的所有内容。

    demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2013-05-20
      • 2022-07-06
      相关资源
      最近更新 更多