REGEX fail with [^] negation group

A place for users to ask each other questions, make suggestions, and discuss Bookends.
Post Reply
mwra
Posts: 48
Joined: Mon Jun 15, 2015 7:01 am

REGEX fail with [^] negation group

Post by mwra »

I checked the reference cited in the manual (http://userguide.icu-project.org/strings/regexp) and this SQL search should return me only those items where user1 (the bibtex key) does not contain a colon:

Code: Select all

(user1 REGEX '[^:]')
Instead it returns all in-scope items.In fact testing further, any test with the standard regex negation group [^...] seems to fail.How do I find a key containing zero colons?

Also, the manual has a typo on page 373. The last example at the top of the page lists "secondaryexample" as a match. this should in fact be "secondary example" with a space between the words, as the regex has a space before 'example' in the match string.
Jon
Site Admin
Posts: 10071
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: REGEX fail with [^] negation group

Post by Jon »

I think the search you're looking for is

(user1 REGEX '[^:]') OR (length(user1) is NULL)

Jon
Sonny Software
mwra
Posts: 48
Joined: Mon Jun 15, 2015 7:01 am

Re: REGEX fail with [^] negation group

Post by mwra »

Sadly, the suggested code returns all items. I only want those that lack a colon. I'm less worried about the number of colons or whether User1 has no value.

The regex is correct - we both use the same. However if I substitute an 'a' for the colon I still don't get all notes where the key lacks an 'a' character. This would imply the negation group regex is not working at all. I'm using BE 13.1.4 on OS 10.14.1.

A linked problem is where is 'user1' mapped to the screen label 'key'. I can't find that in preferences so had to figure it out by comparing the order of fields in the Preferences>Fields tab. It seems the label may be set via the BibTeX tab but that's only obvious after the fact. You can't see any reference to this change to the default to it on the Fields tab which seems the primary reference for this mapping; it would help to have some indication on the latter too.
Jon
Site Admin
Posts: 10071
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: REGEX fail with [^] negation group

Post by Jon »

REGEX searches are handled by the database engine, so it's opaque to me. But I see some erratic behavior, too.

Instead of a REGEX search you can do a Find (Command-F). Set the various options in the second line of the Find dialog to

not -- Text -- characters -- : -- User1

That works for me.

Jon
Sonny Software
Jon
Site Admin
Posts: 10071
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: REGEX fail with [^] negation group

Post by Jon »

I believe the problem with negate search is that it looks at each character, and if *any* is not : it makes a match. Try this search:

user1 NOT regex ':'

Jon
Sonny Software
mwra
Posts: 48
Joined: Mon Jun 15, 2015 7:01 am

Re: REGEX fail with [^] negation group

Post by mwra »

Jon,

Thanks both work. For later readers, in the first case I used a Smart Group with 2 arguments:

1. Text / field is not empty / User1
2. not / Text / characters/ : / User1

I've also managed to nicely adapt the SQL query to use:

user1 NOT REGEX ':\d{4}:'

Which is a last check my keys are in form 'name:yyyy:abbrev'. works like a charm. Over 1100 keys now standardised on a single consistent style. Happiness!
Post Reply