You need to sign in to do that
Don't have an account?
parkerAPT
Case Insensitive Pattern Matcher
Is there a way to make a Pattern case insensitive, like in Java and most other regular expression libraries?
In Java, you can write something like:
Pattern p = Pattern.compile("foobar",Pattern.CASE_INSENSITIVE);
This will match "fOObar" or "Foobar" or any other permutation.
In Apex, it seems like you can only specify the regular expression.
- One solution would be to make the regular expression lowercase and make all strings you match against lowercase. However, if I want to get a case sensitive group, I could not do this elegantly (but can be done).
Thanks
In Java, you can write something like:
Pattern p = Pattern.compile("foobar",Pattern.CASE_INSENSITIVE);
This will match "fOObar" or "Foobar" or any other permutation.
In Apex, it seems like you can only specify the regular expression.
- One solution would be to make the regular expression lowercase and make all strings you match against lowercase. However, if I want to get a case sensitive group, I could not do this elegantly (but can be done).
Thanks
There is! See this post:
http://community.salesforce.com/t5/Apex-Code-Development/Case-insensitive-regular-expressions/m-p/151732/highlight/false#M21444
in your case you would write your expression like this
Pattern p = Pattern.compile('(?i)foobar');