Using Notepad ++ Finds and Replaces Regular Expression

I have an html menu file that contains a list of html pages extracted by the chm decoder.

(7,0,"Icons Used in This Book","final/pref04.html"); (8,0,"Command Syntax Conventions","final/pref05.html"); (9,0,"Introduction","final/pref06.html"); (10,0,"Part I: Introduction and Overview of Service","final/part01.html"); (11,10,"Chapter 1. Overview","final/ch01.html"); (12,11,"Technology Motivation","final/ch01lev1sec1.html"); 

I want to create a "table of contents" file for Caliber from this (an HTML file containing links to all other files in the correct order). The final file should look like this:

 <a href="final/pref04.html">Icons Used in This Book</a><br/> <a href="final/pref05.html">Command Syntax Conventions</a><br/> . . . 

So first I need to remove the prefixes of the regular expression digits, and then add the a href attribute to create the hyperlink and change the URL and the position of the header. Can someone show how to do this with Notepad ++?

+6
source share
1 answer

I think this would do it for you, I'm mac-based, so I don't have notepad ++, but it works in Dreamweaver. Assuming each expression is based on one line.

Search:

 \(.*?"(.*?)","(.*?)".* 

Replace:

 <a href="$2">$1</a><br/> 

File:

 (7,0,"Icons Used in This Book","final/pref04.html"); (8,0,"Command Syntax Conventions","final/pref05.html"); (9,0,"Introduction","final/pref06.html"); (10,0,"Part I: Introduction and Overview of Service","final/part01.html"); (11,10,"Chapter 1. Overview","final/ch01.html"); (12,11,"Technology Motivation","final/ch01lev1sec1.html"); 

After replacing all:

 <a href="final/pref04.html">Icons Used in This Book</a><br/> <a href="final/pref05.html">Command Syntax Conventions</a><br/> <a href="final/pref06.html">Introduction</a><br/> <a href="final/part01.html">Part I: Introduction and Overview of Service</a><br/> <a href="final/ch01.html">Chapter 1. Overview</a><br/> <a href="final/ch01lev1sec1.html">Technology Motivation</a><br/> 

If this is not one change based on the string .* To .*?\n This should stop it after each new line. For readability, you can also add a new line for replacement.

Perhaps also explain the regex if you want to change it ...

The first \ speeds up ( therefore, the regular expression knows to search for a literal and a non-standard grouping of regular expressions. *? Says that it types each character before the first " ; ( . Is any single character, * is zero or more occurrences of the previous character, and ? indicates that it stops at the first occurrence of the next character " ). The last .* says that it will continue to search. ( and ) around the group .*? found the value found in $1 and $2 The number correlates with the order in which it is in regular expression.

+6
source

Source: https://habr.com/ru/post/987703/


All Articles