Sublime Forum

[solved] Replace within a find selection

#1

I’ve got a long list with html code that looks like this:

<li class="parentCat"><a href="https://www.website.com/category" name="left.navi.category.1:category cars"><strong>Cars</strong></a></li>
<li class="parentCat"><a href="https://www.website.com/category" name="left.navi.category.1:category trains"><strong>Trains</strong></a></li>

I need to replace the space within the left.navi.category with a dash “-”. So instead of name="left.navi.category.1:category cars it needs to become name="left.navi.category.1:category-cars.

Is there any way to replace characters within a search selection? Since the document is ± 2000 lines (all with the same makeup as the example above) I’d like to find a way to automate this.

I already found a way to find all the lines with the left.navi.category by using CTRL+H and then look for "name=“left.navi.category.1:[^<]+”. But I’m not sure how to replace the " " with a “-”, is it possible to find and replace within a find?

0 Likes

#2

There are a few different ways of achieving this, but probably the simplest is to click the “Find All” button with your regex search, which will select all the matches, and then do a(nother) Find and Replace, tick “In Selection” and search for space, replacing it with -, and click “Replace All”.

0 Likes

Regex: Match and Remove particular repetead-words from tags
#3

Thanks, works like a charm!

0 Likes