2017-06-05 76 views
0

如何在Notepad ++中「阻止評論」SQL語句?如何在Notepad ++中評論SQL語句?

例如:

CREATE TABLE gmr_virtuemart_calc_categories ( id int(1) UNSIGNED NOT NULL, virtuemart_calc_id int(1) UNSIGNED NOT NULL DEFAULT '0', virtuemart_category_id int(1) UNSIGNED NOT NULL DEFAULT '0' ) ENGINE=MyISAM DEFAULT CHARSET=utf8;

它應與/*開始和*/在記事本+ +使用正則表達式到底包裹製作:

/*CREATE TABLE ... (...) ENGINE=MyISAM DEFAULT CHARSET=utf8;*/

+0

謝謝你澄清我的問題! – gba

回答

1

你只提供一個樣本輸入,所以我不得不從字面上建設模式。如果由於存在其他查詢和/或其他干擾性文本而導致此模式不適合,請更新您的問題。 勾選「匹配大小寫」框。

查找內容:(CREATE[^;]+;)替換爲:/*$1*/

否則,你可以用這個以大寫和結束分號啓動SQL查詢塊:

查找內容:([A-Z][^;]+;)替換:/*$1*/


爲了提高準確性,您可能需要包含^行起始符或在分號後加\r\n或匹配分號前的CHARSET部分。有幾個可以做出的調整。如果不知道更多關於大量文本的信息,我無法對準確性充滿信心。

+0

找到:'(CREATE [^;] +;)替換爲:'/ * $ 1 * /'對我來說非常完美,對我來說更容易理解 - 謝謝! – gba

0

你可以使用遞歸正則表達式。
我認爲NP使用boost或PCRE。
這適用於兩者。

https://regex101.com/r/P75bXC/1

查找(?s)(CREATE\s+TABLE[^(]*(\((?:[^()']++|'.*?'|(?2))*\))(?:[^;']|'.*?')*;)
更換/*$1*/

Explained

(?s)       # Dot-all modifier 
(        # (1 start) The whole match 
     CREATE \s+ TABLE [^(]* # Create statement 
     (        # (2 start), Recursion code group 
      \(
      (?:       # Cluster group 
       [^()']++      # Possesive, not parenth's or quotes 
      |        # or, 
       ' .*? '      # Quotes (can wrap in atomic group if need be) 
      |        # or, 
       (?2)       # Recurse to group 2 
      )*        # End cluster, do 0 to many times 
      \) 
    )        # (2 end) 
            # Trailer before colon statement end 
     (?:       # Cluster group, can be atomic (?>) if need be 
      [^;']       # Not quote or colon 
     |        # or, 
      ' .*? '      # Quotes 
    )*        # End cluster, do 0 to many times 
     ;        # Colon at the end 
)        # (1 end) 
+0

@gba - 爲什麼,不客氣!我希望它對你有用。他們如何解析這些東西真是太神奇了吧?也可能是CREATE [^;] +;'?〜? – sln