嘿,這應該是簡單的,我只是沒有看到它,我想創建一個正則表達式(PERL,Awk,SED/* nix下可用),它會找到領先的現金($),下一個Equal(=),並且處理介於雙引號或單引號的第一個實例與最後一個雙引號或單引號之間的內容。正則表達式在兩個條件後運行
讓我舉幾個例子。
$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
謝謝你們任何人的情況下!
我不想要這個或其他任何var在引號之前,儘管是一個該死的好回答 – ehime
@ehime - if你只需要等式的正確部分,然後將'print'改爲'「$ x [2] \ n」'。 –
我該如何運行/結合我的當前代碼? – ehime