What's wrong with this regex code that works fine in search/replace?

What's wrong with this regex code that works fine in search/replace?

23
Basic UserBasic User
23

    Aug 26, 2008#1

    Getting an error here:

    Code: Select all

    var regexpFind=/.*TextData">(.|\r\n|\n)*</Column>/; /* use a regexp object and not a string, so we don't have to double-escape backslashes */
    The expression works fine in find and replace.

    6,686585
    Grand MasterGrand Master
    6,686585

      Aug 26, 2008#2

      I guess, the problem is the single double quote in your not double quoted search string.
      Best regards from an UC/UE/UES for Windows user from Austria

      23
      Basic UserBasic User
      23

        Aug 26, 2008#3

        The need is to match the data between the Column tags in an example shown below:


        <Column id="1" name="TextData">SELECT ca.*, CASE c.boodle_minkyID WHEN 0
        THEN CASE WHEN ca.name IS NULL THEN 0 ELSE c.minkyID END ELSE CASE
        ca.isBranded WHEN 0 THEN 0 ELSE c.boodle_minkyID END END AS agencyID
        FROM minky_dipsy AS ca WITH (NOLOCK), minky AS c WITH (NOLOCK)
        WHERE ca.minkyID = c.minkyID AND ca.status = 1 AND ca.minkyID =
        1</Column>

        The column tag could also be on one line:

        <Column id="1" name="TextData">SELECT ca.* from DorkNozzle</Column>

        6,686585
        Grand MasterGrand Master
        6,686585

          Aug 27, 2008#4

          Because you need a double quote in your regular expression search string, you must define it as string or the JavaScript engine cannot interpret this line correct. Do you have no syntax highlighting activated for script files? As I copied your code line into a file with extension JS it immediately highlighted everything starting from the single double quote as string, a very good visual indication that there is something wrong in the syntax. Use

          var regexpFind="/.*TextData\">(.|\\r\\n|\\n)*</Column>/";

          and delete the comment which is not correct anymore for this line.
          Best regards from an UC/UE/UES for Windows user from Austria

          262
          MasterMaster
          262

            Aug 27, 2008#5

            You can still define the regexp as Regexp object. But not the double quote that is causing you problems (all though as Mofi describes it, it screws up the syntax highligting) but you need to escape the forward slash in </Column> because the script engine thinks the regexp is terminated at the first forward slash.

            var regexpFind=/.*TextData">(.|\r\n|\n)*<\/Column>/;

            If you configure UE with Javascript Lint it will duly report the error as:

            Code: Select all

            C:\...\temp.js(1): SyntaxError: invalid flag after regular expression
            var regexpFind=/.*TextData">(.|\r\n|\n)*</Column>/;
            ..........................................^
            
            1 error(s), 0 warning(s)