Extract the data between script tag using java regular expression
<p>I want to extract the data given between the script tag. I also made a regex for this but it is not working on this string  -      </p>

<pre><code>&lt;script&gt;
var arrowimages = {
  down: ['downarrowclass', 'Images/arrow-down.gif', 23],
  right: ['rightarrowclass', 'Images/submenu-pointer.png']
}

var jqueryslidemenu = {

  animateduration: {
    over: 400,
    out: 400
  }, //duration of slide in/ out animation, in milliseconds

  buildmenu: function (menuid, arrowsvar) {
    jQuery(document).ready(function ($) {
        var $mainmenu = $("#" + menuid + "&gt;ul")
        var $headers = $mainmenu.find("ul").parent()
        $headers.each(function (i) {
            var $curobj = $(this)
            var $subul = $(this).find('ul:eq(0)')
            this._dimensions = {
              w: this.offsetWidth,
              h: this.offsetHeight,
              subulw: $subul.outerWidth(),
              subulh: $subul.outerHeight()
            }
            this.istopheader = $curobj.parents("ul").length == 1 ? true : false
            $subul.css({
              top: this.istopheader ? this._dimensions.h + "px" : 0
            })
            $curobj.children("a:eq(0)").css(this.istopheader ? {
              paddingRight: arrowsvar.down[2]
            } : {}).append(
              '&lt;img src="' + (this.istopheader ? arrowsvar.down[1] : arrowsvar.right[1]) + '" class="' + (this.istopheader ? arrowsvar.down[0] : arrowsvar.right[0]) + '" style="border:0;top:12px;" /&gt;'
            )
            $curobj.hover(
                function (e) {
                  var $targetul = $(this).children("ul:eq(0)")
                  this._offsets = {
                    left: $(this).offset().left,
                    top: $(this).offset().top
                  }
                  var menuleft = this.istopheader ? 0 : this._dimensions.w
                  menuleft = (this._offsets.left + menuleft + this._dimensions.subulw &gt; $(window).width()) ? (this.istopheader ? -this._dimensions.subulw + this._dimensions.w : -this._dimensions.w) : menuleft
                  if($targetul.queue().length &lt;= 1) //if 1 or less queued animations
                    $targetul.css({
                    left: menuleft + "px",
                    width: this._dimensions.subulw + 'px'
                  }).slideDown(jqueryslidemenu.animateduration.over)
                },
                function (e) {
                  var $targetul = $(this).children("ul:eq(0)")
                  $targetul.slideUp(jqueryslidemenu.animateduration.out)
                }
              ) //end hover
            $curobj.click(function () {
              $(this).children("ul:eq(0)").hide()
            })
          }) //end $headers.each()
        $mainmenu.find("ul").css({
          display: 'none',
          visibility: 'visible'
        })
      }) //end document.ready
  }
}

//build menu with ID="myslidemenu" on page:
jqueryslidemenu.buildmenu("myjquerymenu", arrowimages)

&lt;/script&gt;
</code></pre>

<p>My regex is- <code>&lt;script[^&gt;]*&gt;(.*?)&lt;/script&gt;</code></p>

<p>other normal script tags like  <code>&lt;script type="text/javascript" src="JsFiles/jquery.min.js"&gt;&lt;/script&gt;</code> are retrieved by my regular expression but i don't know why it is not working on that particular string. I needed the data between text to modify that data so grouping is required too. i have also tried jsoup for doing this task -</p>

<pre><code>    Elements scripts = doc.select("script");
 for(Element script: scripts) {
   System.out.println("src " + script);
   String lineread = script.toString();
   String data = script.data();
   if(!data.isEmpty()) {
     System.out.println(data);
     Pattern p = Pattern.compile("\\\"([^\\\"]*)\\\"|'([^']*)'");
     Matcher m = p.matcher(lineread);
     while(m.find()) {
       if(m.group(0).contains(".axd") || m.group(0).contains(".JPG") || m.group(0).contains(".jpg") || m.group(0).contains(".jpeg") || m.group(0).contains(".png") || m.group(0).contains(".js") || m.group(0).contains(".ico") || m.group(0).contains(".gif")) {
         System.out.println("m.g(0) " + m.group(0));
         System.out.println("m.g(1) " + m.group(1));
         String changepath;
         Pattern p1 = Pattern.compile("src=(.*?)&gt;|src=\"(.*?)\"");
         Matcher m1 = p1.matcher(m.group(0));
         if(m1.find()) {
           if(m1.group(0).contains(".axd") || m1.group(0).contains(".JPG") || m1.group(0).contains(".jpg") || m1.group(0).contains(".jpeg") || m1.group(0).contains(".png") || m1.group(0).contains(".js") || m1.group(0).contains(".ico") || m1.group(0).contains(".gif")) {
             System.out.println("inner " + m1.group(0));
             changepath = "\"" + main_url + "" + m1.group(1).replace("\"", "").replace("'", "") + "\"";

             lineread = lineread.replace(m1.group(1), changepath);
             System.out.println("data " + lineread);
           }
         } else {
           changepath = "\"" + main_url + "" + m.group(0).replace("\"", "").replace("'", "") + "\"";

           lineread = lineread.replace(m.group(0), changepath);
           System.out.println("data in src " + lineread);
         }
       }
     }
     script = script.text(lineread);
     System.out.println("final script " + script);

   }
 }
</code></pre>

<p>but the problem in this is the value i am getting in script(the last variable) remove all the spaces that are present in data between the script tag.</p>

<p>so basically i want either a regular expression for getting the data between script tag or how can i get the data without loosing spaces from second solution. </p>