There's probably a more clever way to do this but this pattern works with 
multiple passes. Each Replace All will replace one space per link. Eventually 
it should have a pass where it doesn't replace anything.

Find: (?<=>)(.*?) (.*?)(?=</a>)
Replace: \1\&nbsp;\2

It uses a look behind and a look ahead assertion to find the text between > and 
</a> and then replaces the first space inside.

[fletcher]

> On Jun 26, 2024, at 9:24 AM, [email protected] <[email protected]> wrote:
> 
> Hi all,
> 
> Longtime fan, first time caller. BBEdit's the best.
> 
> I know my way around BBEdit grep searches pretty well, and yet I'm finding 
> myself stumped on what seems like it should be a pretty simple thing.
> 
> I've got a bunch of lines that contain hyperlinks to song titles. In 
> simplified form, they look like this:
> 
> <a href='index.html#All Day Long'>All Day Long</a>
> <a href='index.html#Chosen Time'>Chosen Time</a>
> <a href='index.html#Sooner Than You Think'>Sooner Than You Think</a>
> 
> I chose these specific examples because they have a variable number of spaces 
> within the song names. What I want to do is replace the spaces in the 
> displayed text (that is, between the ">" and the "<") with "&nbsp;" but  I 
> want to not do the same to the spaces within the href= portion of the <a tag.
> 
> I can search with something like:
> >.*?</a>
> and that will match only the portion I want to change.
> 
> Or if it helped, I could chunk the whole line into subpatterns, like:
> ^(<a.*?)(#.*?>)(.*?)(</a>)
> which would then put what I want to change in \3.
> 
> But in either case, what would I put in the Replace field that would allow me 
> to replace only the spaces with something else ("&nbsp;" in this case)? Or, 
> is there some strategy for breaking it up into multiple finds that would get 
> the job done? I've really racked my brain for a while on this and I feel like 
> I must be staring at it but not seeing it.
> 
> Thanks for any ideas!
> 
> Ivan.
> 
> 
> 
> -- 
> 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] 
> <mailto:[email protected]>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/bbedit/d47cdc83-c4c0-4b75-aef3-f7eaed42e442n%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/bbedit/d47cdc83-c4c0-4b75-aef3-f7eaed42e442n%40googlegroups.com?utm_medium=email&utm_source=footer>.

-- 
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 on the web visit 
https://groups.google.com/d/msgid/bbedit/117AAD9B-0FB0-4DA7-8FF6-578E8FDFE14E%40cumuli.com.

Reply via email to