How to avoid special characters in NSString using RegexKitLite?

I am creating a regular expression that uses user input strings, but strings can contain special characters such as. \ Or *, and I want them to be treated as literals and not interpret their special values ​​in the regular expression. I tried this:

NSString *word = [input stringByReplacingOccurrencesOfRegex:@"(\\P{L})" withString:@"\\$1"];

but non-letter characters are converted to "$ 1" instead of the backslash prefix. I tried one and three backslashes in the second member, but they give me the warning “Unknown escape sequence” in Xcode. How can I print a backslash without RegexKitLite, thinking that I am avoiding the dollar sign?

+3
source share
1

, , . ,

\. 

\\. 

\\ 

\\\\
+7

Source: https://habr.com/ru/post/1778501/


All Articles