0

関数内の入力またはスポット (常にラインに沿ったもの):

ワシントン、T. ラッシュで MT0 まで 3 ヤード

to the MT0テキスト " "を取得したい

homeacrynm「MT」は、varまたはawayacrynm関数呼び出しの前に初期化するものと一致します。これが私がこれまでに試したことです:

getEndSpotEugene: function(spot)
    {
        var regex = new RegExp("to the +("+homeacrynm+"|"+awayacrynm+")?([0-9]{1,2})","g");
        var matches = spot.match(regex);
        if (matches)
        {
            pos = matches[matches.length-1]
            matches = pos.match(/to the ([A-Z]+)?([0-9]{1,2})/);
            if (!matches[1])
            {
                matches=[pos,"V",50];   
            }
        }
        else
        {
            return -1;  
        }
        var acr = matches[1];
        var yard = matches[2];
        if (acr == homeacrynm) 
            return "H"+yard;
        else
            return "V"+yard;
    },

例 (1 つの単純なケース):

homeacrynm = "MT"
var giveMe = getEndSpotEugene("Washington, T. rush for 3 yards to the MT11")

giveMeH11 である必要がありますが、何らかの理由でそうではありません。

どこが間違っているのかもよくわかりません。私が見逃しているものはありますか?ありがとうございました!

4

1 に答える 1

0

私はいくつかのログを作成し、次のようにhomeacrynmとawayacrynmを明示的に宣言しました。

  var homeacrynm = "MT";
  var awayacrynm = "H";
  var getEndSpotEugene = function(spot)
  {
      var regex = new RegExp("to the +("+homeacrynm+"|"+awayacrynm+")?([0-9]{1,2})","g");
      console.log(regex);
      var matches = spot.match(regex);
      console.log(matches);
      if (matches)
      {
          pos = matches[matches.length-1]
          matches = pos.match(/to the ([A-Z]+)?([0-9]{1,2})/);
          if (!matches[1])
          {
              matches=[pos,"V",50];   
          }
      }
      else
      {
          return -1;  
      }
      var acr = matches[1];
      var yard = matches[2];
      console.log(acr);
      console.log(yard);          
      if (acr == homeacrynm) 
          return "H"+yard;
      else
          return "V"+yard;
  }

不思議なことに、私はあなたが期待するようにH11を手に入れます!何を得てるの?

于 2012-10-01T16:54:59.433 に答える