sununest
sununest

Reputation: 65

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 first line of the text. i need to get NSRange till that and i dont want to change it to caps.

please suggest solutions.

Upvotes: 2

Views: 422

Answers (1)

zaph
zaph

Reputation: 112857

\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.

Upvotes: 1

Related Questions