Grep searching - how to ignore the first word of the sentence

77 views
Skip to first unread message

Pavel

unread,
Dec 7, 2021, 9:31:58 PM12/7/21
to BBEdit Talk

I searched the whole chapter 8 of the BBEdit manual but no result. 

Would anyone please know what must contain grep so that the first words of the sentence do not appear in the search results? 

Example. 

Potato is good and I have a Potato and the Potato were born well this year. 

I want to find the word Potato with a capital initial letter but omit the first word of the sentence from the result. (Then change the first letter of those words to lowercase.)

So the result of the searching would be just two words, not three.

Potato is good and I have a Potato and the Potato were born well this year. 

Thank you very much

Pavel

Tom Robinson

unread,
Dec 7, 2021, 10:21:15 PM12/7/21
to bbe...@googlegroups.com
You could probably do it with a lookbehind assertion, but would searching for <space>Potato work?


--
This is the BBEdit Talk public discussion group. If you have a feature request or need technical support, please email "sup...@barebones.com" rather than posting here. Follow @bbedit on Twitter: <https://twitter.com/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.
To view this discussion on the web visit https://groups.google.com/d/msgid/bbedit/720ae853-97a1-4d0c-954a-9f0b6a3d2e52n%40googlegroups.com.

Christopher Stone

unread,
Dec 7, 2021, 11:27:42 PM12/7/21
to BBEdit-Talk
On Dec 07, 2021, at 17:50, Pavel <pxc...@gmail.com> wrote:

Would anyone please know what must contain grep so that the first words of the sentence do not appear in the search results? 


Hey Pavel,

Tom's idea is simpler, but you can do this:

Find:

(?<!^)(Potato)

Replace:

\L\1


--
Best Regards,
Chris

jj

unread,
Dec 8, 2021, 4:00:48 AM12/8/21
to BBEdit Talk
It all depends on the definition of a sentence and if you want to match the exact word or words "starting with".

Considering sentences as strings of characters separated by dots and exact word matching then:

Find:

    ([^\.\s]\s+)(Potato)\b
   
Replace:

    \1\l\2

Sample:

Potato is good and I have a Potato and the Potato were born well this year.
Some more text. Potato is good but Potato chips are good too.

With some indent:

    Potato, singular but not Potatoes nor Potatory.
   
HTH

Jean Jourdain

Pavel

unread,
Dec 9, 2021, 11:31:47 AM12/9/21
to BBEdit Talk
Hi and thank you all for your help.
What you all wrote works great.
Chris's advice is probably ideal for my particular case.
Thanks again to everyone.
Pavel

Dne středa 8. prosince 2021 v 10:00:48 UTC+1 uživatel jj napsal:
Reply all
Reply to author
Forward
Message has been deleted
0 new messages