【问题标题】:regex - between optional quotes正则表达式 - 可选引号之间
【发布时间】:2012-01-27 05:08:22
【问题描述】:

要搜索的字符串示例:

name = 'bob'
person=mary
init= 'tim', 
first =sarah,
,name=o'donnel
surny = 'o'doherty',
extend = 'marshall , mathers (111)'

下面的这个正则表达式搜索是错误的:

[ ]*,?[ ]*(.+)[ ]*=[ ]*'?(.*)'?[ ]*(,|;)*[ ]*

正则表达式替换为 2 个组:\1 \2

期望的结果如下:

name bob
person mary
init tim 
first sarah
name o'donnel
surny o'doherty
extended marshall , mathers (111)

伪代码按顺序基本上是:

optional spaces,one optional comma,optional spaces,any characters (grouped),optional spaces,optional spaces,one optional single quote,any characters (grouped),one optional single quote,optional spaces,one optional comma or semicolon,optional spaces

【问题讨论】:

    标签: regex perl unix scripting character-encoding


    【解决方案1】:

    让它不贪心:(.+) -> (.+?)(.*) -> (.*?), demo

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-15
      • 2012-02-09
      • 1970-01-01
      • 2019-04-15
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多