Does NSRegularExpression support case-insensitive partial case?

As the title says, I wonder if NSRegularExpression in both Objective-c and Swift was able to support case-insensitive fuzzy data searches?

Namely, does the pattern (? Ismx) recognize? If not, is there a slight reason for this inability?

I sincerely appreciate your explanation.

+2
source share
1 answer

From the Link to the NSRegularExpression Class :

Table 2 Regular Expression Operators

...

(?ismwx-ismwx:...)
Flag settings. Evaluate the expression in brackets with the specified flags or -disabled ....

(?ismwx-ismwx)
Flag settings. Change the flag settings. Changes apply to part of the template after installation. For example, (? I) changes to case insensitive ...

Example:

 let pattern = "(?i)f(?-i)oo" //Or: let pattern = "(?i:f)oo" let regex = NSRegularExpression(pattern: pattern, options: nil, error: nil)! let string : NSString = "foo, Foo, fOO" regex.enumerateMatchesInString(string, options: nil, range: NSMakeRange(0, string.length)) { (result, flags, stop) -> Void in println(string.substringWithRange(result.range)) } 

Output:

  foo
 Foo

The pattern matches "foo" and "Foo" because "f" is not case sensitive. It does not match "fOO" because "oo" matches case sensitivity.

+5
source

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


All Articles