In my code I make extensive use of regular expression, and my patterns look something like this
regexp = [[NSRegularExpression alloc] initWithPattern:@".*?\\\+.*?\\\+.*?\\\+.*?\\\+.*?\\\+.*?\\\+" options:0 error:nil];
For the escape sequences I get compiler warnings like "Unknown escape sequence +" which is extremely annoying because it is not wrong in my case. How can I get rid of this warning?
You have to many back-slash characters, use:
regexp = [[NSRegularExpression alloc] initWithPattern:@".*?\\+.*?\\+.*?\\+.*?\\+.*?\\+.*?\\+" options:0 error:nil];
To get a \
in a string it needs to be escaped: \\
. So \\\+
applies the first \
to escaping the second \
and the third \
tries to escape the plus sign +
which is an illegal escape.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With