Using notepad++ replace with a wildcard

Im trying to figureoutthe best way to do the replace thing in Notepad++ to replace every instance of

<a href="racks_data_center.html#rack_155">

only the # will change (155-512)

<a onclick="popupCenter('racks_data_center.html', 'myPop1',700,500);" href="javascript:void(0);">

im thinking of replacing

<a href="racks_data_center.html#rack_*\d">


<a onclick="popupCenter('racks_data_center.html', 'myPop1',700,500);" href="javascript:void(0);">

but making sure the regular expression option is selected in the search mode

First, I must mention a warning that using regex to parse html is problematic. Search “html regex” will return a large discussion. Note that regex matches characters, so if there is an extra space then the link will not be matched.

With that said. regex parses text and has some special meaning for some characters. For example . will match any character. So the . before html in the file name will match any character. This can be escaped \. to match only ..

Another point is the character * will match 0 or more of the previous character. So in the example there is the sequence _* which will match 0 or more underscore characters. Instead of * the character + can be used to match 1 or more of the previous character. So changing this part of the regex to rack_\d+ will match the string “rack_” with one or more number characters. (the number 155 is made up of three characters)

regex also has the feature that allows using part of the found string in the results. I noticed that you are not using the rack number in the new link. If you wanted to you could create a capture group by surrounding the characters with () then inserting \1 in the replacement string. So the regex would be :

<a href="racks_data_center\.html#rack_(\d+)">

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.