Find and Replace items which do NOT contain a simple pattern...

96 views
Skip to first unread message

Andy Nickless

unread,
May 14, 2023, 12:29:05 PM5/14/23
to BBEdit Talk
Something that I've been unable to find out is how to skip searching something which already contains a simple pattern:
For instance, to find a number consisting 1-3 digits I use (\d{1,3}) - but how can I AVOID a number of up to 3 digits?
Thanks in advance -
Andy

Kaveh Bazargan

unread,
May 14, 2023, 12:57:20 PM5/14/23
to bbe...@googlegroups.com
can you give examples of strings you want to match and strings you don't want to match?

--
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/4455d2a7-6efe-4183-903e-ea1baa8e091dn%40googlegroups.com.


--
Kaveh Bazargan PhD
Director
Accelerating the Communication of Research
  https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/

Fletcher Sandbeck

unread,
May 14, 2023, 1:04:01 PM5/14/23
to bbe...@googlegroups.com
\d{1,3} matches a sequence of 1 to 3 digits so it will match 1, 12, or 123. 

If you specify a single number in the braces then it will match only that number of digits. \d{3} will match 123, 231, etc.

If you want to match all numbers longer than three digits you can use \d{3,}. This will match 123, 1234, 12345, etc.

Note that \d{3} will still match the start of 1234. You can add word boundaries \b\d{3}\b to correct for this.

[fletcher]


Andy Nickless

unread,
May 14, 2023, 1:09:54 PM5/14/23
to BBEdit Talk
Yes, of course, Kaveh - thanks for your speedy reply - again!
I got this the other day (you helped with it) to find a line of text (or text and numbers) which end with a colon and a space -
<p>(.+?)\:
It's brilliant, but there are occasions when I want to avoid a pattern such as <strong>123</strong>. The number varies, (from 1 to 999) and there may be other numbers, but I want to include those. In other words, avoid lines with numbers within the <strong></strong> tags.

At other times, I want to avoid a certain word (or html).
I hope that makes sense!
Andy

Kaveh Bazargan

unread,
May 14, 2023, 3:11:38 PM5/14/23
to bbe...@googlegroups.com
Sorry, still not clear for me. Does Fletcher's answer work?

Are you saying there are specific numbers you do not want to match, say
<strong>135</strong>
but ones that you do want to match, say
<strong>137</strong>
?

Otherwise can you explain further?

Andy Nickless

unread,
May 14, 2023, 6:05:06 PM5/14/23
to BBEdit Talk
No Kaveh - Unfortunately Fletcher's reply doesn't help.
I'll try to clarify.

In this case, I want to make bold parts of some lines of text which begin with <p> up to where the bold part will end at a colon (:) Any text after the colon won't be bold.

<p>All this text will be bold, as until the first colon: The text after the colon will be normal.</p>

<p><strong>123</strong>Any lines which begin as this one does, will not be changed.</p>
(The number being any combination of 1-3 digits).

I hope that's more clear. Apologies for the lack of clarity.
Andy

Christopher Stone

unread,
May 14, 2023, 6:56:55 PM5/14/23
to BBEdit-Talk
On May 14, 2023, at 11:29, 'Andy Nickless' via BBEdit Talk <bbe...@googlegroups.com> wrote:

Something that I've been unable to find out is how to skip searching something which already contains a simple pattern:
For instance, to find a number consisting 1-3 digits I use (\d{1,3}) - but how can I AVOID a number of up to 3 digits?


Hey Andy,

It's really necessary to provide proper examples when asking for help with regular expressions...

One needs to be able to visualize and test with real-world data to be able to untangle this sort of problem properly.

I can't think of a way using only regex to avoid all of the possible pitfalls – this example using a negative-lookahead will match only the lines in the middle block.



__PATTERN__

<strong>(?>(?:(?!</strong>|\d{1,3}).)*)</strong>

___TEST DATA___

<strong>1</strong>
<strong>10</strong>
<strong>100</strong>
<strong>2000</strong>
<strong>20000</strong>

<strong>Thank you India</strong>
<strong>Thank you terror</strong>
<strong>Thank you disillusionment</strong>

<strong>Thank you frailty 1</strong>
<strong>Thank you consequence 22</strong>
<strong>Thank you thank you silence 33</strong>



The only way I can think of to manage this puzzle in a bombproof way is to script it, and I'd probably use Perl for that.

--
Take Care,
Chris

Jim Straus

unread,
May 14, 2023, 8:46:58 PM5/14/23
to bbe...@googlegroups.com
Someone might have something better, but I think you could use the up to a colon match, and replace with <strong>\1</strong>. This might double strong your numbers.  Then search for <strong><strong>(.*?)</strong></strong> and replace with <strong>\1</strong> to get rid of the duplicate holding.  It’s a two step processes.

-Jim Straus

On May 14, 2023, at 5:05 PM, 'Andy Nickless' via BBEdit Talk <bbe...@googlegroups.com> wrote:

No Kaveh - Unfortunately Fletcher's reply doesn't help.

Rick Gordon

unread,
May 14, 2023, 9:39:59 PM5/14/23
to bbe...@googlegroups.com
Some discussion here
<https://ruby-talk.ruby-lang.narkive.com/dKpNQUAf/inverting-a-regular-expression>
or googling <https://www.google.com/search?q=regex+invert>. But it
involves some coding outside BBEdit.

Rick Gordon

-------
On May 14, 2023 at 6:37:10 PM [-0700], 'Andy Nickless' Via Bbedit Talk
wrote in an email entitled "Find and Replace items which do NOT contain
a simple pattern...":
> --
> 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
> <mailto:bbedit+un...@googlegroups.com>.
> <https://groups.google.com/d/msgid/bbedit/4455d2a7-6efe-4183-903e-ea1baa8e091dn%40googlegroups.com?utm_medium=email&utm_source=footer>.

___________________________________________
RICK GORDON
EMERALD VALLEY GRAPHICS AND CONSULTING
___________________________________________
WWW: http://www.shelterpub.com

Kaveh Bazargan

unread,
May 15, 2023, 2:45:43 AM5/15/23
to bbe...@googlegroups.com
Ah, so no digit dependency at all, right? Does this work:

Search: <p>(.+?):(.+)</p>
replace: <p><strong>\1</strong>:\2</p>

Andy Nickless

unread,
May 15, 2023, 4:19:02 AM5/15/23
to BBEdit Talk
My grateful thanks to those who have patiently tried to help, but I think we're over-complicating it.
(My apologies once more).
It occurred to me just now that what I'm looking for, is lines of text and digits (but not html) between <p> and the colon:
Searching for <p>(\w+): works well if there are no digits - so how can I include text like 22nd, 1st, or even a number on its own (1234 for example?).

I try to make my posts clear, but equally, I don't want to bore people with excess detail.

Kaveh Bazargan

unread,
May 15, 2023, 4:22:25 AM5/15/23
to bbe...@googlegroups.com
Hi Andy

I suggest you give several examples of what should be picked up and made bold, and several of what should not be. Still not clear for me. ;-)

Andy Nickless

unread,
May 15, 2023, 4:40:58 AM5/15/23
to BBEdit Talk
Thanks Kaveh,
Look at this another way...
I want to search within <p> and the colon:

If I use .+? it picks up everything, including stuff I don't want.
Using <p>(\w+): works brilliantly as long as there are no numbers or digits in the line of text - but I want to include these.

So how can I search for words or numbers etc  but no left or right arrows in the result such as < or >?
(I WOULD also like to include punctuation, such as exclamation and question marks, brackets, etc, - if I can).
Thanks - Andy

Kaveh Bazargan

unread,
May 15, 2023, 4:49:21 AM5/15/23
to bbe...@googlegroups.com
Try this one. It matches any characters before colon, but not <>

Andy Nickless

unread,
May 15, 2023, 6:13:42 AM5/15/23
to BBEdit Talk
Thank you once again, Kaveh - that works perfectly!
Best wishes,
Andy

Bruce Van Allen

unread,
May 15, 2023, 11:40:44 AM5/15/23
to bbe...@googlegroups.com
> On May 15, 2023, at 3:13 AM, 'Andy Nickless' via BBEdit Talk <bbe...@googlegroups.com> wrote:
>
> Thank you once again, Kaveh - that works perfectly!
> Best wishes,

Yay!

For future reference, the best way to get help is NOT to try diagnosing the problem into abstractions, but rather to provide a few before and after examples of the specific text you're dealing with, plus any comments needed to clarify your goal for the transformation.

Also, don’t worry abut boring us - the people here who like to answer questions do it because we enjoy puzzle-solving and exercising BBEdit’s capabilities.

— Bruce

_bruce__van_allen__santa_cruz_ca_
> --
> 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/1adbf484-f522-457c-ae49-6558ec336b19n%40googlegroups.com.
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies ● Twitter ● LinkedIn ● ORCID ● @kave...@mastodon.social
> Accelerating the Communication of Research
>
>
> --
> 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/e8c65a54-7efb-44e5-9bbd-06d306f7aa8en%40googlegroups.com.
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies ● Twitter ● LinkedIn ● ORCID ● @kave...@mastodon.social
> Accelerating the Communication of Research
>
>
> --
> 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/6c97dff0-bc37-4ddf-a5db-fe7c1ca23484n%40googlegroups.com.
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies ● Twitter ● LinkedIn ● ORCID ● @kave...@mastodon.social
> Accelerating the Communication of Research
>
>
> --
> 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/a5ba32c6-41ed-473a-bde1-ed430e31b332n%40googlegroups.com.
>
>
> --
> Kaveh Bazargan PhD
> Director
> River Valley Technologies ● Twitter ● LinkedIn ● ORCID ● @kave...@mastodon.social
> Accelerating the Communication of Research
>
>
> --
> 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/7705120f-d94a-4b71-80d6-ed5467e82c11n%40googlegroups.com.

Kaveh Bazargan

unread,
May 15, 2023, 11:44:40 AM5/15/23
to bbe...@googlegroups.com
+1 Bruce!



--
Kaveh Bazargan PhD
Director
Accelerating the Communication of Research
  https://rivervalley.io/gigabyte-wins-the-alpsp-scholarly-publishing-innovation-award-using-river-valleys-publishing-technology/
Reply all
Reply to author
Forward
0 new messages