* find Fact Notes, Text from Source and Source note with a last blank/empty line

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

find Fact Notes, Text from Source and Source note with a last blank/empty line

Post by jimlad68 » 14 Nov 2022 23:11

I am trying to find Fact Notes and Text from Source and Source Note that have a last blank/empty line. Easy enough to find any blank line with 2 enters (paragraph marks).

I can do this directly by editing the Gedcom file in notepad++ (find replace) as the CHAN record seems to come directly after the last CONT but I would rather do it from within FH with say Lua in Search and replace or even a query (I have had a look at GetParagraph but there does not seem an option to find the last.

I have also tried to print/export Fact Notes and Text from Source and Source Note as a long list, but from a query, notes do not export cleanly and usually truncated.
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

User avatar
tatewise
Megastar
Posts: 27074
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: find Fact Notes, Text from Source and Source note with a last blank/empty line

Post by tatewise » 15 Nov 2022 10:41

Yes, the Search and Replace plugin will find those trailing blank lines using Lua Pattern Mode as shown below.

Tick the Note & Description fields and Text from Source fields options to include all types of Note and Text from Source.

The Search: text is two Return/Enter key newline characters followed by plus + and dollar $ that locks the pattern to the end of the field.

S&R.png
S&R.png (52.69 KiB) Viewed 735 times

It wasn't very clear what you wanted to do having found them. Do you want the trailing blank line(s) removed, i.e. the multiple newline characters replaced by just one newline character? If so, then put a single newline in the Replace: box.

BTW:The ¶¶+$ means that the field must end in a newline followed by one or more newlines ¶+, i.e. multiple blank lines.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Re: find Fact Notes, Text from Source and Source note with a last blank/empty line

Post by jimlad68 » 15 Nov 2022 11:23

Thanks will check that out later when I am back with my PC
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Re: find Fact Notes, Text from Source and Source note with a last blank/empty line

Post by jimlad68 » 15 Nov 2022 21:17

I did note this from my notes:
^ – When at the beginning of a pattern, it forces the pattern to match the beginning of a string
$ – When at the end of a pattern, it forces the pattern to match the end of a string

I should have "twigged" as I have often used ^ for beginning of a "line"

Your $ inspired me to experiment.

- Your suggestion looked for 2 blank lines at the end and left 1.
By removing the REPLACE NewlineChar it removed both.

- OR more simply by searching for

+$

Replace with nothing,
that worked for as many "trailing" blank lines as there were.

I wondered why ¶+$ worked when ¶¶+$ did not, but when I looked at other notes with no blank line, none had a alone on the last line, I suppose a means a blank line.

In my testing this seemed to work for last lines with any number of spaces and nothing else, but I am not sure if it would also remove things in other situations in the middle of a few lines. Search

+·+$
(=+space+$)
Replace with nothing

I will add that to my "Tidy Up" check list.

Now I want to do similar to ^ and $ with MSWord Find/Replace Macro to find the beginning/end of a line without using ¶ (^13 etc) so it does not interfere with surrounding formatting.
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

User avatar
tatewise
Megastar
Posts: 27074
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: find Fact Notes, Text from Source and Source note with a last blank/empty line

Post by tatewise » 15 Nov 2022 22:02

Much of what you posted is correct.
jimlad68 wrote:
15 Nov 2022 21:17
I wondered why ¶+$ worked when ¶¶+$ did not, but when I looked at other notes with no blank line, none had a alone on the last line, I suppose a means a blank line.
¶+$ will match one or more consecutive characters.
¶¶+$ will match one followed by one or more consecutive , i.e. two or more consecutive characters.
What to match and what to replace depends on exactly what you want to change, which was unclear in your OP.
I prefer the last line of Note text to be terminated with one but your preference is different.
jimlad68 wrote:
15 Nov 2022 21:17
In my testing this seemed to work for last lines with any number of spaces and nothing else, but I am not sure if it would also remove things in other situations in the middle of a few lines. Search

+·+$
(=+space+$)
Replace with nothing

+·+$
will match one or more consecutive followed by one or more space characters at end of field.
To match any combination of trailing white space characters (newline, space, tab) you should use:

·» ]+$

where the square brackets define a set of characters, so any of them will match and the + means one or more of them.

To remove things from the middle of a few lines you must remove the $ anchor but take care about what you are matching.
e.g. If you match ¶+ and replace with nothing it will remove ALL newline characters so your lines of text will all run together. Also, the last word on one line and first word on next line will have no space between them!
jimlad68 wrote:
15 Nov 2022 21:17
Now I want to do similar to ^ and $ with MSWord Find/Replace Macro to find the beginning/end of a line without using ¶ (^13 etc) so it does not interfere with surrounding formatting.
Remember the ^ and $ anchor to the beginning and end of the whole text, not subsidiary lines.
MS Word Find/Replace does have some sophisticated features.
After invoking the Find or Replace you can click More>> or Advanced Find and then there are many Special codes and also Wild Card options. Click ? for Help.
I'm not sure whether MS Word supports the regular expression features similar to Lua patterns
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
jimlad68
Megastar
Posts: 911
Joined: 18 May 2014 21:01
Family Historian: V7
Location: Sheffield, Yorkshire, UK (but from Lancashire)
Contact:

Re: find Fact Notes, Text from Source and Source note with a last blank/empty line

Post by jimlad68 » 15 Nov 2022 22:53

Thanks, a few more hints and wrinkles: I like the [ ] which I have used in MSWord and other regex

·» ]+$

it also found many "trailing" tabs.
So it does it all in 1 command.
Jim Orrell - researching: see - but probably out of date https://gw.geneanet.org/jimlad68

Post Reply