NSRegularExpression problem for newbie
i am a regular expression newbie. I have a working code using nsregularexpression. i am modifying it a little.
__nameRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"^\\w+" options:NSRegularExpressionCaseInsensitive error:nil];
@"^\w+" what does it refer to ? does it convert first word to capital ?
I have a \r\n in f开发者_运维技巧irst line of the text. i need to get NSRange till that and i dont want to change it to caps.
please suggest solutions.
\w means match a word character. (the double '\' is just escaping a single '\'.
\w+ means match one or more word characters. Assuming greedy matching it will match as many word characters as possible (longest match).
Specifically \w means unicode
[\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}]
which means (in order)
Letter lowercase, Letter uppercase, Letter titlecase, Letter other, Number decimal digit.
精彩评论