How to count number of notes with REGEX?

A place for users to ask each other questions, make suggestions, and discuss Bookends.
Post Reply
pepemac
Posts: 20
Joined: Sat Sep 19, 2015 6:41 am

How to count number of notes with REGEX?

Post by pepemac »

Hello
Anyone know REGEX code that allow us count number of notes for each reference and filter records by number chosen?
For example:
Show me references that have five or (more/less) notes, or between 10 and 20 notes, for instance.

Thanks
Jon
Site Admin
Posts: 10291
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: How to count number of notes with REGEX?

Post by Jon »

I am far from an SQL/REGEX expert, but I can make a small contribution that might get you started.

This will find any reference with non-newline characters in the notes field (this is entered in the SQL search box):

notes REGEX '.'

To find notes with more than one note (as determined by there being two returns in a row -- it doesn't test to see if there is actually text after the two returns), use this

notes REGEX '.' AND notes REGEX '\n\n'

As for specifying the number of instances of 2 returns in a row, I know it can be done but not how to do it.

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

Re: How to count number of notes with REGEX?

Post by Jon »

I've done a little better. This search seems to find a references with entries in the notes field with a minimum number of two return separators between them. In the example below, Bookends would find notes with 4 or more notecards. At least that's how it's working for me.

notes REGEX '.' AND notes REGEX '[\n\n.*]{3}'

Perhaps someone else can offer a better solution.

Jon
Sonny Software
pepemac
Posts: 20
Joined: Sat Sep 19, 2015 6:41 am

Re: How to count number of notes with REGEX?

Post by pepemac »

For me don't work.
I get references with 1, 2 or more notes :cry:
I'm curious with one thing.
Why notes are in the same table that references and not in other related table?
I'm sure that you have good reasons for this.
Thank you.
Jon
Site Admin
Posts: 10291
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: How to count number of notes with REGEX?

Post by Jon »

You can search the Internet for Regex tips (which is what I did) and see if you can come up with a better solution.

Notes in the same table because they belong to that particular reference, there never was any intention for no sharing of notes between references.

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

Re: How to count number of notes with REGEX?

Post by Jon »

I've tested this in Refs -> SQL/Regex Search and it works

notes regex '.' AND notes regex '[\n\n.*]{2,}'

It counts the number of times the pattern 2 returns followed by text occurs in the notes field and returns true if the there a specified number or more. In the example, above Bookends will find the reference if there are 2 or more occurrences of the pattern. Note that this means Bookends will find references with 3 notecards or more (the first notecard is not preceded by returns).

If it doesn't work for you I have no explanation.

Jon
Sonny Software
pepemac
Posts: 20
Joined: Sat Sep 19, 2015 6:41 am

Re: How to count number of notes with REGEX?

Post by pepemac »

I'm sorry if I seem a heavy, but...
https://www.dropbox.com/s/04q6nx0oh1fqo ... 1.mp4?dl=0
pepemac
Posts: 20
Joined: Sat Sep 19, 2015 6:41 am

Re: How to count number of notes with REGEX?

Post by pepemac »

I think I know what is the problem.
Those notes which has inside asterisk "Moi importante*****" is considered as valid and is considered like various notes (as much notes as asterisks has the note)

For instance:

#@1 high intensity aerobic activity, children, VO2max
>The aim of this study was to investigate the effect of high intensity aerobic activity in five weeks, two sessions per week, on children’s VO2peak. Additionally we wanted to test whether ten-year old boys were able to sustain intensity over 80 % of reart ratepeak (HRpeak) for a relative long period of time (up to 4 minutes), using aerobic games and play.
IMPORTANTE*****


Is only one note, but regex expressión consider that are six notes (the note + one note for each asterisk).
pepemac
Posts: 20
Joined: Sat Sep 19, 2015 6:41 am

Re: How to count number of notes with REGEX?

Post by pepemac »

In fact, the problem happen when any note has regex metacharacters at the end of any line (before carriage return)
Jon
Site Admin
Posts: 10291
Joined: Tue Jul 13, 2004 6:27 pm
Location: Bethesda, MD
Contact:

Re: How to count number of notes with REGEX?

Post by Jon »

Then try removing the .* from the search.

notes regex '.' AND notes regex '[\n\n]{2,}'

You're going to have to do some research and experimenting, too. This is a power user feature and definitely not my area.

Jon
Sonny Software
pepemac
Posts: 20
Joined: Sat Sep 19, 2015 6:41 am

Re: How to count number of notes with REGEX?

Post by pepemac »

Ok.
I'm working on it, but, at the moment...
If anybody else has any idea about it...welcome!!!

Thank you, Jon.
Post Reply