Grep Find and Replace -- One Piece Missing

38 views
Skip to first unread message

Bill Kochman

unread,
Jul 22, 2025, 7:26:38 AMJul 22
to bbe...@googlegroups.com
Greetings friends,

I am trying to do a global find and replace on a folder of 1,154 BBEdit documents. The operation needs to be very precise, as otherwise, it will REALLY mess me up, and will result in hours — if not days — of unnecessary work on my part.

At the moment, all of my BBB articles have a header at the top, part of which looks like this:

Last Updated: Jan. 10, 2011

The Year 2000 Hype, Aliens, Spirit Helpers, Channelers And
Esoteric Knowledge, Propagation Of New Age Thought, Sheldon
Nidle, UFO Mass Landings, Photon Belt, The Ascension Point,
False Prophets & Charlatans Exposed By Time, The 2012 Hype,
Stanley A. Fulham And The Transcendors, Weeds And Parable Of
Wheat & Tares, Measuring Rod Of God's Word, Strong Delusion,
Beware Of Time-Based Predictions, Verify The Reliability Of
Source Information, Failed Predictions Weaken Faith In God's
Word, Modern Scoffers And Christ's Return, Satan's Scheme To
Discredit True Prophets Of God, True Faith Does Not Require
Evidence Signs Or Miracles, Modern Apostasy, Mary Apparition
In Wisconsin, Decline Of Roman Catholicism And Mary Worship,
Evil Generation Seeks A Sign, Jewish Elders Demanded A Sign,
Jewish Religious Elders Concealed Evidence Of Resurrection

The body of text you see above is obviously different in each article, and followed by three blank lines. Then the main body of the article begins.

To give you a quick background, I have been working on creating my own GPT at chatgpt.com for the past two weeks. However, my GPT has MAJOR problems with parsing text, accurate data retrieval, misattributions, hallucinations, inventions, etc.

So one thing I though to do was to clarify that the above text after the date is actually the synopsis before the main body of each article. So what I am trying to do is to add the word “Synopsis", following by a divider on a new line, then the above text, followed by another divider on a new line, followed by three blank lines. In other words, the end product should look like this:


Last Updated: Jan. 10, 2011

Synopsis:

<==========================================================>

The Year 2000 Hype, Aliens, Spirit Helpers, Channelers And
Esoteric Knowledge, Propagation Of New Age Thought, Sheldon
Nidle, UFO Mass Landings, Photon Belt, The Ascension Point,
False Prophets & Charlatans Exposed By Time, The 2012 Hype,
Stanley A. Fulham And The Transcendors, Weeds And Parable Of
Wheat & Tares, Measuring Rod Of God's Word, Strong Delusion,
Beware Of Time-Based Predictions, Verify The Reliability Of
Source Information, Failed Predictions Weaken Faith In God's
Word, Modern Scoffers And Christ's Return, Satan's Scheme To
Discredit True Prophets Of God, True Faith Does Not Require
Evidence Signs Or Miracles, Modern Apostasy, Mary Apparition
In Wisconsin, Decline Of Roman Catholicism And Mary Worship,
Evil Generation Seeks A Sign, Jewish Elders Demanded A Sign,
Jewish Religious Elders Concealed Evidence Of Resurrection

<==========================================================>




The dates are different for every article, as is the text of the synopsis. As such I have tried to use something like the following in the find field:

Last Updated: (.+?)\. (.+?), ([0-9][0-9][0-9][0-9])\n\n(.+?)\n\n\n\n

The problem is that I cannot figure out what to use to cover the main text part of the synopsis which is AFTER ([0-9][0-9][0-9][0-9])\n\n and BEFORE \n\n\n\n. You can see that I have added a final (.+?) for the main text of the syopsis. However, when I use that, the text is not being highlighted, so that is apparently wrong.

In the replace field, I am currently using the following, where \4 represents the main text part of the synopsis:

Last Updated: \1\. \2, \3\n\nSynopsis:\n\n<==========================================================>\n\n\4<==========================================================>\n\n\n\n

Not only can I not find the right syntax to represent the text part of the synopsis, but If I run it just like that, with the actual text included in the replace field -- instead of the final (.+?) -- BBEdit throws up this error:

Find-Replace-Error.jpg

Rod Buchanan

unread,
Jul 22, 2025, 9:48:34 AMJul 22
to bbe...@googlegroups.com
Try this:

Search
(?s)^(Last Updated: [A-Z][a-z][a-z]\. \d\d?, \d\d\d\d)\n\n(.+)\n\n\n\n

Replace
\1\n\nSynopsis:\n\n<==========================================================>\n\n\2\n\n<==========================================================>\n\n\n\n

— 
Rod





--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.
<Find-Replace-Error.jpg>
If I hit the “Replace” button anyway, the results are this, and the text body of the synopsis is wiped out completely:

Last Updated: Jan. 10, 2011

Synopsis:

<==========================================================>

<==========================================================>



Those are three blank likes above this line. So what am I doing wrong? How do I get it to recognize the changing text in the synopsis section, so that it replaces everything, but includes the right synopsis text for each article when I do a global find and replace?

Thanks to anyone who can help me figure out the last piece of the puzzle.

Kind regards,

Bill Kochman


--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.

Bill Kochman

unread,
Jul 22, 2025, 10:05:01 AMJul 22
to bbe...@googlegroups.com
Thanks Rod, but absolutely nothing is being selected when I use that in the find field.

Question: Why do you replace the month with three patterns when just one will suffice as I did with (.+?)?

Question: Why use \d\d for the day of the month, when sometimes it will just be one digit and not two? Again, wouldn’t (.+?) be better to cover any scenario?

Question: Why is (?s)^( needed before Last Updated when Last Updated will already be added to the replacement as I have it now?

I am far from a pro when it comes to greg patterns, and I am not challenging you. I am simply trying to understand why you made the choices that you did.

My original find pattern works fine, all except for printing the text part of the synopsis. I really just need to know what to put instead of that last (.+?) before the \n\n in my original pattern.

Thanks.


Bill Kochman

unread,
Jul 22, 2025, 10:21:25 AMJul 22
to bbe...@googlegroups.com
Okay, I have made a little bit of progress by using the following instead in the find field:

Last Updated: (.+?)\. (.+?), (.+?)\n\n(.+)

The problem is that it is ONLY selecting the first line in the text of the synopsis body like this:

Last Updated: Jan. 10, 2011

Year 2000 Hype, Bogus Aliens Spirit Helpers Channelers And

So, when I use this in the replace field …..

 Last Updated: \1\. \2, \3\n\nSynopsis:\n\n<==========================================================>\n\n\4\n\n<==========================================================>\n\n\n\n\n

It produces this:

Last Updated: Jan. 10, 2011

Synopsis:

<==========================================================>

Year 2000 Hype, Bogus Aliens Spirit Helpers Channelers And

<==========================================================>





Esoteric Knowledge, The Blasphemous Urantia Book, Dolores
Cannon And "Conversations With Nostradamus", False Angels Of
Light And Other Questionable Sources, Propagation Of New Age
Thought, Sheldon Nidle's Bogus UFO Mass Landings Prediction,
An Imaginary Photon Belt, The Ascension Point, False Prophets
And Charlatans Exposed By Time Itself, Scriptures Concerning
False Prophets And Teachers, A Plethora Of Modern Deceivers,
Christendom Also Infiltrated, The Social Networks Deception,
2012 Hype, Deceivers' Changing Narratives, Birds Of A Feather
Flock Together For Support And Validation, Charlatan Tom Horn
And Money-Making Book Writing Scam, Stanley A. Fulham And His
Transcendors, Weeds And Parable Of Wheat And Tares, Measuring
Rod Of God's Word, God Will Send Us Strong Delusion If That's
What We Truly Want, Beware Of Time-Based Predictions, Verify
Reliability Of Source Information, Failed Predictions Weaken
Faith In God's Word, Modern Scoffers And Christ's Return,
Satan's Scheme To Discredit True Prophets Of God, True Faith
Does Not Require Evidence Signs Or Miracles, Modern Apostasy,
Mary Apparition In Wisconsin, Decline Of Roman Catholicism And
Mary Worship, Evil Generation Seeks A Sign, Jewish Elders
Demanded A Sign, Jewish Religious Elders Concealed Evidence Of
Resurrection


So how do I get it to select ALL of the text in the synopsis before doing the replace?

Kind regards,

Bill Kochman

On Jul 22, 2025, at 11:41 PM, Rod Buchanan <nana...@gmail.com> wrote:

flet...@cumuli.com

unread,
Jul 22, 2025, 10:22:10 AMJul 22
to bbe...@googlegroups.com
The pattern .+ won't match multiple lines by default. You can change it to [\s\S]+ and it will match the entire block.

Last Updated: (.+?)\. (.+?), ([0-9][0-9][0-9][0-9])\n\n([\s\S]+?)\n\n\n\n

Rod Buchanan

unread,
Jul 22, 2025, 10:23:24 AMJul 22
to bbe...@googlegroups.com

It tested what I sent you again and it worked fine.  You do have Grep checked in the search dialog?

Q1:  Because I wanted to. :). Either will work; mine will only match three letters where the first is capitalized.

Q2:   ‘\d’ will only match digits, and the ‘?’ makes the second digit optional, so it wil match “1” or “10".

Q3: (?s) allows ‘.’ to match line breaks.  '^' says "Last Updated" starts at the beginning of the line.  If that's not always the case remove it.

HTH,

— 
Rod





Bill Kochman

unread,
Jul 22, 2025, 10:27:53 AMJul 22
to bbe...@googlegroups.com
Ha! Fletcher and Rod, I got it to work right before Fletcher wrote using this in the find field:

(?s)^Last Updated: (.+?)\. (.+?), (.+?)\n\n(.+)

And this in the replace field:

Last Updated: \1\. \2, \3\n\nSynopsis:\n\n<==========================================================>\n\n\4\n<==========================================================>\n\n\n\n\n


That works perfectly, and is a lot shorter than my previous attempt, and your attempts as well. Here is what it produces:

Last Updated: Jan. 10, 2011

Synopsis:

<==========================================================>

Year 2000 Hype, Bogus Aliens Spirit Helpers Channelers And
Esoteric Knowledge, The Blasphemous Urantia Book, Dolores
Cannon And "Conversations With Nostradamus", False Angels Of
Light And Other Questionable Sources, Propagation Of New Age
Thought, Sheldon Nidle's Bogus UFO Mass Landings Prediction,
An Imaginary Photon Belt, The Ascension Point, False Prophets
And Charlatans Exposed By Time Itself, Scriptures Concerning
False Prophets And Teachers, A Plethora Of Modern Deceivers,
Christendom Also Infiltrated, The Social Networks Deception,
2012 Hype, Deceivers' Changing Narratives, Birds Of A Feather
Flock Together For Support And Validation, Charlatan Tom Horn
And Money-Making Book Writing Scam, Stanley A. Fulham And His
Transcendors, Weeds And Parable Of Wheat And Tares, Measuring
Rod Of God's Word, God Will Send Us Strong Delusion If That's
What We Truly Want, Beware Of Time-Based Predictions, Verify
Reliability Of Source Information, Failed Predictions Weaken
Faith In God's Word, Modern Scoffers And Christ's Return,
Satan's Scheme To Discredit True Prophets Of God, True Faith
Does Not Require Evidence Signs Or Miracles, Modern Apostasy,
Mary Apparition In Wisconsin, Decline Of Roman Catholicism And
Mary Worship, Evil Generation Seeks A Sign, Jewish Elders
Demanded A Sign, Jewish Religious Elders Concealed Evidence Of
Resurrection

<==========================================================>


Kind regards,

Bill Kochman


--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.

bruce linde

unread,
Jul 22, 2025, 10:36:58 AMJul 22
to bbe...@googlegroups.com
On Jul 22, 2025, at 4:27 AM, Bill Kochman <wordwe...@gmail.com> wrote:
I am trying to do a global find and replace on a folder of 1,154 BBEdit documents.The operation needs to be very precise, as otherwise, it will REALLY mess me up, and will result in hours — if not days — of unnecessary work on my part.

make at least one backup copy of your folder before trying anything else 














--
This is the BBEdit Talk public discussion group. If you have a feature request or believe that the application isn't working correctly, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Mastodon: <https://mastodon.social/@bbedit>
---
You received this message because you are subscribed to the Google Groups "BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bbedit+un...@googlegroups.com.

Bill Kochman

unread,
Jul 22, 2025, 10:40:24 AMJul 22
to bbe...@googlegroups.com
Bruce, oh, most definitely! Most definitely, my friend!  :)

Kind regards,

Bill Kochman


Reply all
Reply to author
Forward
0 new messages