1 Reply Latest reply on Aug 12, 2014 12:33 PM by bend@hydraforce.com

    Backslashes getting stripped out of my regex

    bend@hydraforce.com

      I am trying to automate some find/replace routines in dreamweaver using javascript.

       

      dreamweaver.setUpFindReplace({ 

              searchString: '<table width="\d+', 

              replaceString: '<table width="100%"', 

              searchWhat: "document", 

              searchSource: true, 

              useRegularExpressions: true 

          }); 

          dreamweaver.replaceAll();

       

      This query gets passed as: <table width="d+

       

      Problem: when the query string is passed to the setUpFindReplace object, the backslashes get stripped out. Backslashes are key to regular expressions. How do I get them passed from JavaScript to Dreamweaver?

       

      I am using CS6

       

      Ben

        • 1. Re: Backslashes getting stripped out of my regex
          bend@hydraforce.com Level 1

          I am still looking for a smart person to answer, but in case anyone else is having same problem I found a work-around.

           

          I think Java uses the backslash as an escape character and so it is not passing it to Dreamweaver. The only thing I found that works is to set a variable with the regex text, and escaping all the backslashes, then passing the variable to Dreamweaver.

           

          var myFind = '<table width="\\d+"'

           

          dreamweaver.setUpFindReplace({

                  searchString: myFind

                  replaceString: '<table width="100%"',

                  searchWhat: "document",

                  searchSource: true,

                  useRegularExpressions: true

              });

              dreamweaver.replaceAll();

           

          Note: double backslash \\d+ and single quotes ' " " ' used because query string contains double quotes.

           

          I tried escaping the double quotes in the search string \" but this did not work for the same reason.

           

          Ben (not a Java developer)