1 Reply Latest reply on Jun 7, 2012 7:08 AM by Rothrock

    Regular expressions help

    Rothrock Level 5

      I'm using a RegExp class (http://www.jurjans.lv/flash/RegExp.html) to do some regular expression in AS2. But I'm not very good at it.

       

      var str:String="What if there are other variables, such as possible <a class='gloss' href='asfunction:_root.handle, confounding variables'><b>confounding variables</b></a> which could explain at least some of the relationship between the two variables? Here <a href='' target='_blank'>is another link</a>.\n<a class='gloss' href='asfunction:_root.handle, confounding variables'>confounded variables</a>"

       

      var reg1:RegExp = new RegExp("<a.*gloss.*href=[\'\"]?([^\\\'\">]+)>+(.*</a>)", "ig");

       

      var obj:Object = reg1.exec(str);

       

      while (obj != null) {

                for(var a in obj){

                          if(!isNaN(a)){

                          trace(a+": "+obj[a]);

                          }

                }

                trace(newline);

                obj = reg1.exec(str);

      }

       

      And this traces:

       

      2: <b>confounding variables</b></a>

      1: asfunction:_root.handle, confounding variables'

      0: <a class='gloss' href='asfunction:_root.handle, confounding variables'><b>confounding variables</b></a>

       

      2: confounded variables</a>

      1: asfunction:_root.handle, confounding variables'

      0: <a class='gloss' href='asfunction:_root.handle, confounding variables'>confounded variables</a>

       

      I'm trying to get the href and the "friendly link" part of the anchor tag (but only for anchors that have a class of gloss).

       

      As you can see I'm almost there, but I'm getting the extra </a> and the extra ' on the two examples. I tried putting the ) before the </a> but that just broke it. (Of course that could be because this class doesn't work properly, but I'm guessing that isn't the case.)

       

      Anybody really good with regular expressions who can help me out?