Using regex with a variable in the pattern

Using regex with a variable in the pattern

HI,

I am trying to match a pattern with a variable in the string like so:

  1. $(document).ready(function(){
                $.get('inputQueryExamples.txt',function(data){
                    var queryString = data;
                    var cleanString = "";
                    var db = '';
                    $('#database-list').change(function(){
                       db = $('#database-list').val();
                       console.log(db);
                       //put code in here to select pattern, replace un-needed stuff
                       cleanString = queryString.match("/(^DATABASE:" + db + "\r\n)(^NL.*)/gm");
                      
                       for (i=0; i<cleanString.length; i++){
                        $('#what').append(cleanString[i]+'<br>')
                    }
                    }); // end change













I can match the pattern just fine without the variable and without using quotation marks, but my array ends up as null when I try to add quotes and the variable.  Here is a sample of text I am reading:


  1. QUERY:1
    DATABASE:geoquery
    NL:What are the capitals of the states that border the most populated states?
    SQL:something
    DR:
    root(ROOT-0, What-1)
    cop(What-1, are-2)
    det(capitals-4, the-3)
    nsubj(What-1, capitals-4)
    det(states-7, the-6)
    prep_of(capitals-4, states-7)
    nsubj(border-9, states-7)










So the idea is to read the list that has several databases, select just the DATABASE and NL  based on user selected db and then clean the string up so I can pass the array which in it's final version will be just he string after NL: to autocomplete. All is fine except I can't seem to insert the db variable into my regex pattern. Any insight would be appreciated. Thanks