Sakthimuthiah
Sakthimuthiah

Reputation: 2636

How to use NSPredicate to find an NSString begins with numbers or special characters in ios?

Could you please help, how to use NSPredicate to find an NSString beginsWith numbers or other special characters (But not begin with alphabets)? I want to sort an array name that contains any numbers and special characters. Advance thanks for help.

Upvotes: 0

Views: 589

Answers (1)

Nils Ziehn
Nils Ziehn

Reputation: 4331

You should be able to use the MATCHES keyword:

[NSPredicate predicateWithString:@"self MATCHES [^a-zA-Z]+.*"]

You can find more docu here:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-215868

and the definition of how to define the regex here:

http://userguide.icu-project.org/strings/regexp

Upvotes: 2

Related Questions