Question: There are lines:

```
echo "1111111111111; 2222222222; 8; 2; 34,12,2,3,5,1; UNKNOW;"

```

or

```
echo "1111111111111; 2222222222; 8; 2; 34,12,2,3,5,1,5,12,45,34; UNKNOW;"

```

or

```
echo "1111111111111; 2222222222; 8; 2; 3; UNKNOW;"

```

How to take the value of the last character ";" and to the last comma ","?

Answer: 
So your best bet is to give yourself a bit of delay. As noted by Akash, you have to choose the delay time you find acceptable. You also need to make sure that the request is only made after the delay.

Here is one way to do it:

```
//In your controller
var _timeout;

$scope.fetchSearchResults = function(){

    //We will clear the previous timeout because a key has been pressed
    clearTimeout(_timeout);

    //Set the timeout - if no key is pressed, it will execute. Else the line above will clear it.
    _timeout =  setTimeout(function(){
        var keyword = $scope.searchKeyword.name;
        //Do your AJAX request here

        //We have delayed the request by 400ms - but you can change it as you please.
    }, 400);
}

```

Your HTML:

```
<!-- Then in your HTML something similar to: -->
<input ng-model="searchKeyword.name" ng-keyup="fetchSearchResults()" />

```

**Edit:**

If you want to go the 'pure' angular way, you'd do it like this:

```
//In your controller
//NOTE: make sure you've injected $timeout into your controller
var _timeout;

$scope.fetchSearchResults = function(){

    //We will clear the previous timeout because a key has been pressed
    $timeout.cancel(_timeout);

    //Set the timeout - if no key is pressed, it will execute. Else the line above will clear it.
    _timeout =  $timeout(function(){
        var keyword = $scope.searchKeyword.name;
        //Do your AJAX request here

        //We have delayed the request by 400ms - but you can change it as you please.
    }, 400);
}

```
You already accepted the answer but I want to share some code with you.

```
myapp.factory('formService', ['$http', '$filter', '$q', '$timeout', function ($http, $filter, $q, $timeout) {
    var service = {};
    service.delayPromise = null;
    service.canceler = null;
    service.processForm = function (url, formData, delay) {
        if (service.delayPromise)
          $timeout.cancel(service.delayPromise);
        if (service.canceler)
          service.canceler.resolve();
        service.canceler = $q.defer();
        service.delayPromise = $timeout(function (service) {
          return service;
        }, delay, true, service);
        return service.delayPromise.then(function (service) {
          service.delayPromise = null;
          return $http({
              method  : 'POST',
              url     : url,
              timeout : service.canceler.promise,
              data    : formData
          });
        })
    }
    return service;
]);

```

What does this do. It provides `formService` having `processForm` function, with accepts `url`, `formData` and `delay`.

`processForm` function delays submitting with `$timeout` service. If there are already exist delayed or pending submission it just cancels it.

And in your controller.

```
myapp.controller('myCtrl', ['formService', function (formService) {
    $scope.formData = {};
    $scope.pageData = {};
    $scope.$watchCollection('formData', function (formData, oldData, scope) {
      if (!angular.equals(formData, oldData)) {
        var event;
        formService.processForm(formData, event, 500).then(function (response) {
          if (response.data instanceof Object)
            angular.copy(response.data, scope.pageData);
        });
      }
    });
}]);

```