typedef NS_OPTIONS(NSUInteger, NSRegularExpressionOptions) {
NSRegularExpressionCaseInsensitive = 1 << 0, /* 不區(qū)分大小寫 */
NSRegularExpressionAllowCommentsAndWhitespace = 1 << 1, /* 忽略匹配項(xiàng)中的空格 如果模式中有 # 則只匹配 # 前半部的內(nèi)容 */
NSRegularExpressionIgnoreMetacharacters = 1 << 2, /* 逐字匹配 */
NSRegularExpressionDotMatchesLineSeparators = 1 << 3, /* 如果不使用這個(gè)選項(xiàng) . 是不能匹配換行符的*/
NSRegularExpressionAnchorsMatchLines = 1 << 4, /* 允許 ^ 和 $ 匹配每行的開始結(jié)束 */
NSRegularExpressionUseUnixLineSeparators = 1 << 5, /* 只允許 \n 作為換行符 */
NSRegularExpressionUseUnicodeWordBoundaries = 1 << 6 /* 使用Unicode TR#29作為邊界 */
};
NSRegularExpressionAnchorsMatchLines 實(shí)例
字符串@"Hello orld\nthis is a \nHelloaworlda\n string"
注意字符串中的\n
如果模式為@"^H"
結(jié)果為:
Paste_Image.png
如果模式為@"^H.*d$""
結(jié)果為:
Paste_Image.png
如果模式為@"^H.*(d|a)$"
結(jié)果為:
Paste_Image.png