Expanding on Rich's suggestion, a BBEdit Find and Replace grep solution is:
Find:
\A(?s)(?!.*?<section id="main_content">)(.*?)<section>
Replace:
\1<section id="main_content">
This is probably a better solution than my previously posted perl one liner
text factory in that it checks first there isn't already a <section
id=“main_content"> {the negative lookahead assertion (?!.*?<section
id="main_content">)} in the file. If there isn't one, it then proceeds on
with finding the first <section>, and, if found, replacing it with <section
id="main_content">.
On Thursday, May 7, 2026 at 10:58:08 AM UTC-7 Rich Siegel wrote:
> On 7 May 2026, at 9:29, Neil Faiman wrote:
>
> > Well, at least I read the fine manual and saved myself the humiliation
> of publicly asking whether there was a way to selectively search in the set
> of files that matched a previous multi-file search. (Of course there is.
> Just select the previous search results from the “Results Browsers” list in
> the “Search in:” chooser.)
> >
> > But I couldn’t find this one in the manual. I have a bunch of HTML
> files. Some of them have multiple <section> elements. I want to add a
> property to the first <section> tag in each file. I.e., before
>
> According to the user manual, on page 205 there's a list of positional
> assertions, one of which is "\A" which matches the beginning of the file.
> So, you could probably use something like "\A.+?<section" to find the
> beginning of the first `<section` to occur in the file, and go from there.
>
> R.
>
> --
> Rich Siegel Bare Bones Software, Inc.
> <[email protected]> <https://www.barebones.com/>
>
> Someday I'll look back on all this and laugh... until they sedate me.
>
--
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
"[email protected]" 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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/bbedit/50dc91a1-1a84-4a04-af26-1281e4a146edn%40googlegroups.com.