I have a regular expression that searches strings and then wraps them within certain html tags. The problem is that two Turkish characters (İ and ı) do not get matched against their lower or upper cases. So they cannot be wrapped properly.
To be more precise:
- i and even İ is not matched against İ (it probably becomes “I”)
- I is not matched against ı (it probably becomes “i”)
Example:
Search term is İskendername.
The string contains it exactly as it is (İskendername) but there are no matches at all.
Here is my code:
NSString *regex_pattern = [[NSArray arrayWithObjects:@"(", search_term, @")(?![^<>]*>)",nil] componentsJoinedByString:@""];
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:regex_pattern options:NSRegularExpressionCaseInsensitive error:&error];
string_to_be_searched = [regex stringByReplacingMatchesInString:string_to_be_searched options:0 range:NSMakeRange(0, [stringByReplacingMatchesInString:string_to_be_searched length]) withTemplate:@"<div class=""highlight"">$1</div>"];
Solved it myself. Here is how:
There was no way I could get any kind of NS.. options to support Turkish characters. A lossy conversion causes defect in my rendered content. So here is how I sorted it out:
As I have stated, there is this problem that -I- is understood as -i- and -i- is treated as I but that is not the case with Turkish alphabet. We have a lowercase -ı- and an uppercase -İ-.
What I have done was changing my regular expression. So basically I went through all the letters in the NSString and replaced problematic ones (I and i) with [iİıI] so my regular expression would accept them regardless of their having a dot on top or not !
Here is the code in case someone needs it..