Ionic 2 + Regex


#1

Good evening,

I implemented a service to consume data through an API. I get a text and inside this text a URL appears.

What I wanted was to regex treat this text and return only the URL.

Is it possible to help me in the function question to get a string and apply regex and return the result?

This all in ionic 2.

Thank you very much.


#2

Can you share some code?
What do you have, what have you tried?

http://regexr.com/


#3

In ionic 1 i have this code:

var myApp = angular.module(‘myApp’, []);
myApp.filter(‘regex’, function() {
return function(val){
var RegExp = /src="(https?://.*.(?:png|jpg))/;
var match = RegExp.exec(val);
return match[1];
};
});
myApp.controller(‘ctrl’, function($scope){
$scope.user = {‘author’: "src=“https://4.bp.blogspot.com/-HAIQLJZKnhI/WJhyvjkFjPI/AAAAAAAADWw/q1XXwzV4kQoN7qJ3GkT1-mIS-eSjm6EEwCLcB/s640/elias3.jpg”};
});

html:

{{user.author | regex }}

but i need to do this in ionic 2, but i can’t do it.


#4

Look at using Angular Pipes to achieve this.