Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,9 @@
|
|||
NSString *str = @"I am a string";
|
||||
NSString *regex = @".*string$";
|
||||
|
||||
// Note: the MATCHES operator matches the entire string, necessitating the ".*"
|
||||
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
|
||||
|
||||
if ([pred evaluateWithObject:str]) {
|
||||
NSLog(@"ends with 'string'");
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
NSString *str = @"I am a string";
|
||||
if ([str rangeOfString:@"string$" options:NSRegularExpressionSearch].location != NSNotFound) {
|
||||
NSLog(@"Ends with 'string'");
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
NSString *orig = @"I am the original string";
|
||||
NSString *result = [orig stringByReplacingOccurrencesOfString:@"original"
|
||||
withString:@"modified"
|
||||
options:NSRegularExpressionSearch
|
||||
range:NSMakeRange(0, [orig length])];
|
||||
NSLog(@"%@", result);
|
||||
10
Task/Regular-expressions/Objective-C/regular-expressions-4.m
Normal file
10
Task/Regular-expressions/Objective-C/regular-expressions-4.m
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"string$"
|
||||
options:0
|
||||
error:NULL];
|
||||
NSString *str = @"I am a string";
|
||||
if ([regex rangeOfFirstMatchInString:str
|
||||
options:0
|
||||
range:NSMakeRange(0, [str length])
|
||||
].location != NSNotFound) {
|
||||
NSLog(@"Ends with 'string'");
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
for (NSTextCheckingResult *match in [regex matchesInString:str
|
||||
options:0
|
||||
range:NSMakeRange(0, [str length])
|
||||
]) {
|
||||
// match.range gives the range of the whole match
|
||||
// [match rangeAtIndex:i] gives the range of the i'th capture group (starting from 1)
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
NSString *orig = @"I am the original string";
|
||||
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"original"
|
||||
options:0
|
||||
error:NULL];
|
||||
NSString *result = [regex stringByReplacingMatchesInString:orig
|
||||
options:0
|
||||
range:NSMakeRange(0, [orig length])
|
||||
withTemplate:@"modified"];
|
||||
NSLog(@"%@", result);
|
||||
Loading…
Add table
Add a link
Reference in a new issue