Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 124
Registered: ‎09-06-2010
My Device: Not Specified
Accepted Solution

Widget Find API: regex case-insensitivity does not work

I'm attempting to use the blackberry.find and blackberry.pim.Contact Widget APIs to lookup a contact. 

 

I need the contact to be found if the specified filter string is anywhere in the field, regardless of case.  (I need the query to be case-insensitive).

 

I have a contact, firstName field = "Norman".

 

I'm using REGEX method (the only one that would work in this case, I think), with these regex expressions to try and match "Norman":

 

".*Norm.*" matches

".*norm.*"  does not match

 

So I tried the regex (?i) flag in the expression, and the find doesn't work at all.

 

 

var fe = new blackberry.find.FilterExpression("firstName", "REGEX", ".*(?i)norm.*"); // causes blackberry.pim.Contact.find() to fail

The API doc says "Please refer to java.lang.String.matches() API for details on how to create the correct regular expression..." Well, case-insensitivity has been there for a while.

 

 

Is case-insensitivity not supported? If not, well....that would suck.

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget Find API: regex case-insensitivity does not work

Hi jtyberg,

 

I do remember some sort of specific regex that is needed for case insensitivity... I have one of our developers looking into it.

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Developer
Posts: 124
Registered: ‎09-06-2010
My Device: Not Specified

Re: Widget Find API: regex case-insensitivity does not work

Thanks, Neil. 

 

Any news on this?  We're about to tag a release and I'd love for case-insensitive search to work before we do.

Developer
Posts: 185
Registered: ‎08-17-2008
My Device: Red BlackBerry Z10
My Carrier: Vodafone

Re: Widget Find API: regex case-insensitivity does not work

[ Edited ]

you can try with:

 

 

/string/i

 

more info: http://www.w3schools.com/jsref/jsref_regexp_i.asp

 

let us know if works fine 

 

Josep Maria
Developer
Posts: 124
Registered: ‎09-06-2010
My Device: Not Specified

Re: Widget Find API: regex case-insensitivity does not work

No, the JavaScript /i flag is not working, and based on the Widget API docs for blackberry.find.FilterExpression, I wouldn't expect it to. 

 

I believe the regex is being performed by Java under the covers, no?  If not, why would the API docs say  to follow the java.lang.String.matches regex conventions?

 

To review, I have a contact, firstName field = "Norman".  So far, I've tried the following regex in FilterExpression:

 

".*Norm.*"     // matches

".*norm.*"     // does not match

"/.*norm.*/i"  // does not match

"/norm/i"      // does not match

".*(?i)norm.*" // causes Contacts.find to fail

 


Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: Widget Find API: regex case-insensitivity does not work

I had asked one of the guys on the team who had experienced some difficulty getting the case insensitive capability to work.  They had come up with a work around that is a little hacky but did the trick

 

 

var hack = "";
var searchText = searchField.value;for (var i = 0; i < searchField.value.length; i++)
{
  hack = hack + "[" + searchField.value[i].toLowerCase() + searchField.value[i].toUpperCase() + "]";
}

var fe = new blackberry.find.FilterExpression("firstName", "REGEX", hack + "[a-zA-Z_0-9_\\s]*");

var contacts = blackberry.pim.Contact.find(fe, "firstName", null, null, true);

 

They created a character set that contained both the lowercase and uppercase versions of the letter.

Then we added a character set that included everything to the end of it.  There may be a better way to do it.  
Hopefully the idea helps a little.

 

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Developer
Posts: 124
Registered: ‎09-06-2010
My Device: Not Specified

Re: Widget Find API: regex case-insensitivity does not work

Excellent, Tim. 

 

If I wasn't so regex illiterate, I might have thought of it myself. 

 

Now,

 

".*norm.*"

 

is turned into:

 

".*[nN][oO][rR][mM].*"

 

Works like a charm.

Developer
Posts: 314
Registered: ‎03-28-2012
My Device: Curve 9360, Playbook, BB10 Dev Alpha
My Carrier: TMN

Re: Widget Find API: regex case-insensitivity does not work

I just bumped into this same problem today.

Should we still use Tim's hack or is there a nicer way to do it? I tried a few ways, but they all failed.

 

thanks!

Nuno