Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Regular expression

  • 20-04-2016 06:14PM
    #1
    Registered Users, Registered Users 2 Posts: 208 ✭✭


    Looking for a regex that would search sql scripts for

    Any instance of the words create alter or drop
    But exclude comments /** or --

    Some success with (Alter)*(create)
    Can't find an example (in a hurry to produce a list of objects promoted to test) that could do this.

    Any help or expressions appreciated.

    Whitey


Comments

  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    You want a regex to include in a program, or do you want a script to generate something? Do you want to change these verbs or do you want to simply highlight them? For example using grep you could do this:
    grep -i "create\|alter\|drop" filename.sql
    

    Of course, the choice of tools is limited to whatever is available on your chosen platform, so Windows is very poor, while Mac and Linux/UNIX are fine.


  • Closed Accounts Posts: 2,828 ✭✭✭5rtytry56


    OP, what flavour of SQL are you using?
    MySQL, SQL Server


  • Registered Users, Registered Users 2 Posts: 208 ✭✭whiteboard


    the files to be searched are in a folder structure
    was looking to us the 'find in file' feature in VS which I find far more reliable than windows search.

    requirements
    search all files in a folder/sub-folder structure
    for all files containing instances create alter or drop

    of course - open to other methods of doing this


  • Registered Users, Registered Users 2 Posts: 1,275 ✭✭✭bpmurray


    Try the following, using either Linux, or cygwin or similar on Windows
    grep -ril "create\|alter\|drop" *
    
    It will return a list of files containing one of the strings, case insensitive, recursing into subdirectories


  • Registered Users, Registered Users 2 Posts: 1,110 ✭✭✭Skrynesaver


    In Linux/Cygwin, with checks for comments
    for $file in $(find /folder/subfolder -type f)
    do
      perl -ne '$in_comment++ if/\/\*/;$incomment-- if /\*\//;if (! $incomment){ if (print /(create|alter|drop)/ && !/--.+(create|alter|drop));}' 
    done
    


  • Advertisement
Advertisement