In my experience, by far the easiest and simplest solution for this arises when you just try to find and replace a single instance of a space in urls at a time.

Something like this search/replace pair (I didn't test it):

  (\bhref="[^" ]*) ([^"]*\.png")

  \1_\2

That example is just for spaces, not accents, and replaces the first occurrence of a literal space in the url with an underscore.

You can run that with a replace-all op for the first space in each url, and then hit replace-all again for each additional space, until it says there aren't any, so eg if urls have no more than 3 spaces each then its 3 replace-all.

This works as long as your search/replace is idempotent, you are replacing with something different than what you're replacing.

As for accents, you can deal with those with a similar process.

-- Darren

On 2023-07-09 1:52 p.m., Roland Küffner wrote:
You might have a hard time figuring out a pattern for this (as I guess that the amount of white space in the file names might differ and the file names may not follow a strict structure). You could write a script for the task. Or – if it was a one-shot-task – I would do the following steps:

1. Search for: href="(.+?)"     replace with   \1    (using Grep): choose "Extract" – this gives you a new file with all href-Strings in it
2. In the new file: Copy all text
3. Replace all whitespace with _ (an underscore)
3. (for Accents and other stuff add additionals search-replace steps here)
4. Add a tab to each line (you could use the "Prefix/Suffix" command in the "Text" menu for that 5. Mark the column left of the tab ("column zeor") with a rectangular selection (check the manual if you don't know how to do this)
6. Paste the copied text

Now you have a file with the structure
<old file name with spaces><tab><old_file_name_without_spaces>
Save this file and use it as a ad-hoc batch-search-replace source on your orignal file: To do this, choose "Text" > "Canonize …". with your generated file as a source.

That might just take a few minutes and may be an alternative for getting a script right – if you have a lot of different files to process, a script solution may be the wiser choice.

Roland



On Sat, Jul 8, 2023 at 4:03 PM David Puente wrote:

    Hi folks,
    I need to find some trick to rename the text:

         <resource type="webcontent"
    identifier="g989516e6a95da788733f48e98192a620" href="web_resources/Anotación
    2019-07-08 151143.png">

    I need find all the .png names removing spaces and accents... Is there any
    pattern to make it possible? Thanks!!!!

--
This is the BBEdit Talk public discussion group. If you have a feature request or need 
technical support, please email "supp...@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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/67c4128c-a894-f276-b65b-04096f4bb649%40darrenduncan.net.

Reply via email to