0

I am accessing the instagram API to fetch photos that a specific user has liked and the first comment that said user has posted. However I only want to retrieve the URL from the text for example, the user tellasaur first comment is:

"text":"Check out this link http://www.domain.com",

I only want to retrieve http://www.domain.com. Here is my code so far:

So I want to apply a regex on this part {{p.comments.data|getFirstCommentFrom:'tellasaur'}}"

but not sure how.

JS

 angular.module('app',[])
    .filter('getFirstCommentFrom',function(){
      return function(arr, user){
        for(var i=0;i<arr.length;i++)
        {
          if(arr[i].from.username==user)
            return arr[i].text;
        }
        return '';
      }
    })
    .controller('TestCtrl', function($scope){
      $scope.pics = [
        { "images":{
                "low_resolution":{
                   "url":"https:\/\/scontent.cdninstagram.com\/hphotos-xaf1\/t51.2885-15\/s320x320\/e15\/11243658_841091872640638_1858051687_n.jpg",
                   "width":320,
                   "height":320
                },

             },
     "comments":{
                "count":38,
                "data":[
                   {
                      "created_time":"1436314585",
                      "text":"Check out this link http://www.domain.com",
                      "from":{
                         "username":"tellasaur",
                         "profile_picture":"https:\/\/igcdn-photos-b-a.akamaihd.net\/hphotos-ak-xfp1\/t51.2885-19\/11142181_1606991566225969_1204610350_a.jpg",
                         "id":"174270894",
                         "full_name":"kristella"
                      },
                      "id":"1024203434844916571"
                   },
                   {
                      "created_time":"1436317671",
                      "text":"Wow",
                      "from":{
                         "username":"sbcarol2002",
                         "profile_picture":"https:\/\/igcdn-photos-b-a.akamaihd.net\/hphotos-ak-xfp1\/t51.2885-19\/10707061_359756607505353_826681437_a.jpg",
                         "id":"1280059782",
                         "full_name":"Susan Long"
                      },
                      "id":"1024229322726738700"
                   },
                   {
                      "created_time":"1436320519",
                      "text":"\ud83d\udc93 dreamyy",
                      "from":{
                         "username":"veekster",
                         "profile_picture":"https:\/\/igcdn-photos-h-a.akamaihd.net\/hphotos-ak-xtf1\/t51.2885-19\/11117059_1743047859255223_204225114_a.jpg",
                         "id":"31179150",
                         "full_name":"Victoria Wright"
                      },
                      "id":"1024253210688915485"
                   }

                ]
             }
         }
      ]
    });

HTML NG-LOOP

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script>
<div ng-app="app" ng-controller="TestCtrl">
  <li ng-repeat="p in pics">
    <a href="{{p.comments.data|getFirstCommentFrom:'tellasaur'}}" target="_blank"><img ng-src="{{p.images.low_resolution.url}}" /></a>

  <p></p>
  </li>
</div>
user1937021
  • 10,151
  • 22
  • 81
  • 143

1 Answers1

0

See this answer on how to regex match urls in text, your solution is in there somewhere

Community
  • 1
  • 1
Obi
  • 3,091
  • 4
  • 34
  • 56