mardi 4 août 2015

Angularjs filter with regex

I have the following regex to match a URL:

/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/

I need to apply this to a filter so it only matches and grabs the URL from a value:

I want to add it to this part in particular:

return arr[i].text;

Filter

    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 '';
  }
})



{{p.comments.data|getFirstCommentFrom:'machinas_test'}}

Not sure how to add this.

Aucun commentaire:

Enregistrer un commentaire