嘿伙计们,这应该很简单,我只是没有看到它,我想创建一个正则表达式(在 PERL、Awk、SED / *nix 下可用),它将在找到领先的现金 ($) 后运行,下一个相等 (=) 并处理双引号或单引号的第一个实例与双引号或单引号的最后一个实例之间的内容。
让我举几个例子。
$this = 'operate on some text in here'; # operates between single quotes
$this = "operate on some text in here"; # operates between double quotes
$this = 'operate "on some text" in here'; # operates between single quotes
$this = 'operate \'on some text\' in here'; # operates between outer single quotes
我尝试了一些非常糟糕的正则表达式。但只是无法让它正确匹配。
这是我将其插入的内容,以防万一有人感兴趣
printf '$request1 = "select * from whatever where this = that and active = 1 order by something asc";\n' |
grep '{regex}' * |
perl -pe 's/select/SELECT/g ; s/from/\n FROM/g ; s/where/\n WHERE/g ; s/and/\n AND/g ; s/order by/\n ORDER BY/g ; s/asc/ASC/g ; s/desc/DESC/g ;' | ## enter through file with all clauses
awk '{gsub(/\r/,"");printf "%s\n%d",$0,length($0)}' ## take first line convert to whitespace, use on following lines
多谢你们!