Question: So I am using the `preg_match()` function to extract the SRC file name of an image and that part is working well. 

The problem though is it isn't stopping at the closing quotation marks of the src field. It keeps going to including "some" other stuff in the image tag but then just stops. I really just want the src URL only. 

```
preg_match('/<img.+src=[\'"](?P<src>.+)[\'"].*>/i', $rss, $image);
echo $image['src'];

```

Answer: 
Make `UITextField` delegate and paste this below code :-

// in -init, -initWithNibName:bundle:, or similar

```
NSCharacterSet *blockedCharacters = [[[NSCharacterSet alphanumericCharacterSet] invertedSet] retain];

- (BOOL)textField:(UITextField *)field shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)characters
{
    return ([characters rangeOfCharacterFromSet:blockedCharacters].location == NSNotFound);
}

```

// in -dealloc

```
[blockedCharacters release];

```

Hope it helps you
you can use an `NSRegularExpression` like so:

```
    NSString *string1 = @"abc123";
    NSString *string2 = @"!abc123";
    NSError *error = NULL;
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^a-z0-9]" options:NSRegularExpressionCaseInsensitive error:&error];

    NSUInteger numberOfMatches = [regex numberOfMatchesInString:string1 options:0 range:NSMakeRange(0, [string1 length])];
    NSLog(@"string 1 matches: %ld", numberOfMatches);

    numberOfMatches = [regex numberOfMatchesInString:string2 options:0 range:NSMakeRange(0, [string1 length])];
    NSLog(@"string 2 matches: %ld", numberOfMatches);

```

and change the pattern `@"[^a-z0-9]"` to suit the characters you want to check for. The `^` means "not in this set", so if any matches are found the field should fail validation.