This page has:
In this tutorial, we have a classic output of data shown in columns but with only space as separator between each columns
Hello Print Hello
Youhou Print Youhou
We want to transform it in a markup language such as wikipedia, markdown and add a pipe character | to delimit the columns. The expected output is the following:
| Hello | Print Hello |
| Youhou | Print Youhou |
When you copy/paste text in Notepad, the first thing that you want to see if the end of line. By default, the non-visible end of line character are:
If you manipulate a text file that was created on Linux on a Windows system, you may get the linux.
To discover them with notepad,
Example:
To open the replace screen, you type Ctrl+H or in the menu Search > Replace
The most important part on this screen is the Search Mode options that set the type of text of the input that you have written in the Find what field.
If you have selected:
Below is the regular expression that we have created to capture the two columns.
They are enclosed in parenthesis in order to create a group and capture the text in the next step. Enclosing all characters in group is not necessary but we have done it to understand how you can refer to a group in the next step when you replace.
(\w*)(\s*)(.*)(\r\n){0,1}
where:
Example:
Don't check the check box ( . matches newline ) because our regular expression applies to each line.
The replace expression uses what's called backreference in order to select the group of text and replace it in a regular expression process called substitution
In the Replace with field, we have entered the below substitution expression
| \1 | \3 |\4
where:
The fully qualified expression for substitution is
${n}
and must be used when:
After hitting the replace button,
You should get this output:
| Hello | Print Hello |
| Youhou | Print Youhou |
This is achieve with the negation character ^ of a class
Example with the - minus. Take all characters until a minus is found:
([^-]*).*
\1
Example of input:
libX11-1.6.5
lksctp-tools-1.0.17
mailcap-2.1.41
gives this output:
libX11
lksctp
mailcap
Notepad++ uses the Boost Library (C++). For the whole regex pattern format, you may have to refer to it.