加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

coreData增删改查正则

发布时间:2020-12-14 01:57:32 所属栏目:百科 来源:网络整理
导读:coreData增删改查正则 百度30分钟学会正则表达式 #if 0 b 是正则表达式规定的一个特殊代码(好吧,某些人叫它元字符, metacharacter ),代表着单词的开头或结尾,也就是单词的分界处。虽然通常英文的单词是由空格,标点符号或者换行来分隔的,但是 b 并

coreData增删改查正则

百度30分钟学会正则表达式

#if 0

b是正则表达式规定的一个特殊代码(好吧,某些人叫它元字符,metacharacter),代表着单词的开头或结尾,也就是单词的分界处。虽然通常英文的单词是由空格,标点符号或者换行来分隔的,但是b并不匹配这些单词分隔字符中的任何一个,它只匹配一个位置。

现在bhib.*bLucyb的意思就很明显了:先是一个单词hi,然后是任意个任意字符(但不能是换行),最后是Lucy这个单词。

0dd-dddddddd匹配这样的字符串:以0开头,然后是两个数字,然后是一个连字号“-”,最后是8个数字(也就是中国的电话号码。当然,这个例子只能匹配区号为3位的情形)

0d{2}-d{8} 这里d后面的{2}({8})的意思是前面d必须连续重复匹配2(8)

1.常用的元字符

代码说明

.匹配除换行符以外的任意字符

w匹配字母或数字或下划线或汉字

s匹配任意的空白符

d匹配数字

b匹配单词的开始或结束

^匹配字符串的开始

$匹配字符串的结束

比如一个网站如果要求你填写的QQ号必须为5位到12位数字时,可以使用:^d{5,12}$

2.常用的限定符

代码/语法说明

*重复零次或更多次

+重复一次或更多次

?重复零次或一次

{n}重复n

{n,}重复n次或更多次

{n,m}重复nm

Windowsd+匹配Windows后面跟1个或更多数字

^w+匹配一行的第一个单词(或整个字符串的第一个单词,具体匹配哪个意思得看选项设置)

-(BOOL)createNewPersonWithImage:(NSData *)aImage xing:(NSString *)aXing xingP:(NSString *)aXingP
ming:(NSString *)aMing mingP:(NSString *)aMingP company:(NSString *)aCompany phone:(NSInteger)aPhone email:(NSString *)aEmail url:(NSString *)aUrl
{
BOOL result=NO;
if ([aXing length]==0||[aMing length]==0) {
NSLog(@"First and Last names are mandatory.");
return NO;
}
ContactBook *newContactPerson=[NSEntityDescription insertNewObjectForEntityForName:@"ContactBook" inManagedObjectContext:self.managedObjectContext];
if (newContactPerson==nil) {
NSLog(@"Failed to create the new person.");
return NO;
}
newContactPerson.image=aImage;
newContactPerson.xing=aXing;
newContactPerson.xingP=aXingP;
newContactPerson.ming=aMing;
newContactPerson.mingP=aMingP;
newContactPerson.company=aCompany;
newContactPerson.phone=[NSNumber numberWithInteger:aPhone];
newContactPerson.email=aEmail;
newContactPerson.url=aUrl;
NSError *savingError=nil;
if ([self.managedObjectContext save:&savingError]) {
return YES;
}else{
NSLog(@"Failed to save the new person. Error = %@",savingError);}
return result;
}


+(NSArray *)findAll
{
//从coreData数据库读取数据
AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context=[appDelegate managedObjectContext];
NSError *error;
NSFetchRequest *request=[[NSFetchRequest alloc]init];
NSEntityDescription *entityDes=[NSEntityDescription entityForName:@"ContactBook" inManagedObjectContext:context];
[request setEntity:entityDes];
NSSortDescriptor *sortXing=[[NSSortDescriptor alloc]initWithKey:@"xingP" ascending:YES];
NSSortDescriptor *sortMing=[[NSSortDescriptor alloc]initWithKey:@"mingP" ascending:YES];
NSArray *sortArray=[[NSArray alloc ]initWithObjects:sortXing,sortMing,nil];
request.sortDescriptors=sortArray;
NSArray *persons=[context executeFetchRequest:request error:&error];
return persons;
}
+(void)deleted:(ContactBook *)person
{
AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context=[appDelegate managedObjectContext];
[context deleteObject:person];
NSError *savingError;
[context save:&savingError];//执行完删除操作后,存储上下文,更新数据库中的内容
}
+(NSArray *)findByName:(NSString *)name
{
AppDelegate *appDelegate=[[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context=[appDelegate managedObjectContext];
NSError *error;
NSFetchRequest *request=[[NSFetchRequest alloc]init];
NSEntityDescription *entityDes=[NSEntityDescription entityForName:@"ContactBook" inManagedObjectContext:context];
[request setEntity:entityDes];
NSPredicate *pred=[NSPredicate predicateWithFormat:@"ming like [cd]%@",[NSString stringWithFormat:@"*%@*",name]];
[request setPredicate:pred];
NSArray *persons=[context executeFetchRequest:request error:&error];
return persons;
}
+(BOOL)checkEmaliAddress:(NSString*)address{
NSString *emailRegex=@"^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$";
NSPredicate *p=[NSPredicate predicateWithFormat:@"SELF MATCHES%@",emailRegex];
return [p evaluateWithObject:address];
}



- (void)viewDidLoad

{

[superviewDidLoad];

//初始化管理器。

manager=[[CLLocationManageralloc]init];

manager.delegate=self;

manager.distanceFilter=1000;

manager.desiredAccuracy=kCLLocationAccuracyBest;

[managerstartUpdatingLocation];//开始当前服务。

//初始化地图。

mapView1=[[MKMapViewalloc]initWithFrame:CGRectMake(0,0,320,460)];

// mapView1.delegate=self;

mapView1.mapType=MKMapTypeStandard;

[self.view addSubview:mapView1];

// [mapView1 release];

}

-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{

NSLog(@"chenggongle");

mapView1.region=MKCoordinateRegionMake(CLLocationCoordinate2DMake(40+0.002,116.34+0.014),MKCoordinateSpanMake(0.001,0.001));

//添加注解。

myAnnotation=[[MyAnnotationalloc]init];

myAnnotation.coordinate=CLLocationCoordinate2DMake(40+0.002,116.34+0.014);

myAnnotation.title=@"金马大厦";

myAnnotation.subtitle=@"博看文思";//这里如果还想添加图片按钮等则需要代理。

[mapView1addAnnotation:myAnnotation];

[myAnnotationrelease];

}

-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{

for (MKPinAnnotationView *pinView in views) {

if ([pinView.annotation.title isEqualToString:@"Current Location"]) {

pinView.pinColor=MKPinAnnotationColorRed;

pinView.rightCalloutAccessoryView=nil;

continue;

}

//其他定位的注释是紫色带着一个按钮。

pinView.pinColor=MKPinAnnotationColorPurple;

UIButton *button=[UIButtonbuttonWithType:UIButtonTypeDetailDisclosure];

[button addTarget:selfaction:@selector(go:) forControlEvents:UIControlEventTouchUpInside];

pinView.rightCalloutAccessoryView=button;

UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,30, 30)];

imageView.image=[UIImage imageNamed:@"fanqie.jpg"];

pinView.leftCalloutAccessoryView=imageView;

[imageView release];

}

}

-(void)go:(id)sender{

NSLog(@"chegnsagdfsf");

}

#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>

#import "MyAnnotation.h"

@interface MyMapViewController : UIViewController<CLLocationManagerDelegate,MKMapViewDelegate>

@property(retain,nonatomic)CLLocationManager *manager;//定位用的。

@property(retain,nonatomic)MKMapView *mapView1;//显示地图用的。

@property ( retain , nonatomic ) MyAnnotation *myAnnotation;

#import <Foundation/Foundation.h>

#import <MapKit/MapKit.h>//继承注解需要这个头文件。

@interface MyAnnotation : NSObject<MKAnnotation>

@property (nonatomic) CLLocationCoordinate2D coordinate;

@property (nonatomic,copy) NSString *title;

@property (nonatomic,copy) NSString *subtitle;

NSString *match=@"^/w+@/w+(/./w+){1,2}$";//匹配邮箱。

NSString *match=@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}";//匹配邮箱。

NSPredicate *predicate=[NSPredicate predicateWithFormat:@"SELF MATCHES %@",match];

NSLog(@"((((((()))))))%@",textField1.text);

if ([predicate evaluateWithObject:textField1.text]) {

NSLog(@"匹配成功");

}

else{

NSLog ( @" 匹配失败 " );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读