You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.9 KiB

//
// MOBFRegex.h
// MOBFoundation
//
// Created by vimfung on 15-1-20.
// Copyright (c) 2015年 MOB. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
*
*
* @param captureCount
* @param capturedStrings
* @param capturedRanges
* @param stop
*
* @return
*/
typedef NSString *(^MOBFReplacingOccurrencesHandler) (NSInteger captureCount, NSString *const capturedStrings[captureCount], const NSRange capturedRanges[captureCount], volatile BOOL * const stop);
/**
- MOBFRegexOptionsNoOptions:
- MOBFRegexOptionsCaseless:
- MOBFRegexOptionsComments: #
- MOBFRegexOptionsIgnoreMetacharacters:
- MOBFRegexOptionsDotAll: .
- MOBFRegexOptionsMultiline: ^$
- MOBFRegexOptionsUseUnixLineSeparators: \n为唯一的行分隔符
- MOBFRegexOptionsUnicodeWordBoundaries: 使Unicode TR#29
*/
typedef NS_ENUM(NSUInteger, MOBFRegexOptions)
{
MOBFRegexOptionsNoOptions = 0,
MOBFRegexOptionsCaseless = 1 << 0,
MOBFRegexOptionsComments = 1 << 1,
MOBFRegexOptionsIgnoreMetacharacters = 1 << 2,
MOBFRegexOptionsDotAll = 1 << 3,
MOBFRegexOptionsMultiline = 1 << 4,
MOBFRegexOptionsUseUnixLineSeparators = 1 << 5,
MOBFRegexOptionsUnicodeWordBoundaries = 1 << 6,
};
/**
*
*/
@interface MOBFRegex : NSObject
/**
*
*
* @param regex
* @param string
* @param block
*
* @return
*/
+ (NSString *)stringByReplacingOccurrencesOfRegex:(NSString *)regex
withString:(NSString *)string
usingBlock:(MOBFReplacingOccurrencesHandler)block;
/**
*
*
* @param regex
* @param options
* @param range
* @param string
*
* @return YES NO
*/
+ (BOOL)isMatchedByRegex:(NSString *)regex
options:(MOBFRegexOptions)options
inRange:(NSRange)range
withString:(NSString *)string;
/**
*
*
* @param regex
* @param string
*
* @return
*/
+ (NSArray *)captureComponentsMatchedByRegex:(NSString *)regex
withString:(NSString *)string;
@end