Download Find & Replace It! User Manual

Transcript
Find & Replace It!
User Manual
you can inject these captured fragments into your replacement pattern. This is done with a %1, %2,
…, %9 pattern. Where the number that follows the percent sign is the capture index. %0 is a
special, implicit capture that includes the full matched expression.
Let's imagine we have a CSV file containing contacts like in the following snippet:
First Name: John; Family Name: Smith; Phone: ...
First Name: Mike; Family Name: Dupont; Phone: ...
We want to swap the first two columns. Here we have to capture two variable expressions (first
name and family name) and move them around. Here is an easy way to do it.
Find:
(First Name: [^;]+); ( Family Name: [^;]+)
The parentheses in expression above will capture two fragments of every matched occurrences in
the CSV file.
Replace with:
%2; %1
The replacement pattern above is a dynamic text that varies for every matched occurrences. In fact
%1 will be replaced by the content matched by the first parentheses scope. Idem with %2 and the
second parentheses scope.
If you use %n where n is greater than the number of captures, then @{__INJECTION__}#n will
be inserted in the replaced text. If you need to replace some text with a literal %n in a situation
where you captured some texts with your regexp, you'll need escaping the %n sequence. This can
easily be done by adding a % sign in front of the sequence. Note that the escapement only applies
in front of a digit (i.e.: 0 to 9). Everywhere else the escapement is not processed. Here are some
examples:
Text to process Find
Replace with
Result
ab cd
(\w+) %1
ab cd
56 78
(\d+)
%1%2
56@{__INJECTION__}#2 78@{__INJECTION__}#2
56 78
(\d+)
%1%%2
56%2 78%2
56
\d+
%%1
%1
56
(\d+)
%%1
%1
56 78
(\d+)
%%%1
%56 %78
56 78
(\d+)
%%%%1
%%1 %%1
56 78
(\d+)
%%%%2
%%2 %%2
56 78
(\d+)
%%%%%1
%%56 %%78
56 78
(\d+)
%%%%%2
%%@{__INJECTION__}#2 %%@{__INJECTION__}#2
ab
(\w+) %z %1
%z ab
ab
(\w+) %%z %%1
%%z %1
ab
(\w+) %%%z %%%1 %%%z %ab
In the examples above, the pattern \w+ matches any sequence of one or more letters or digits.
The same applies to digits only with the pattern \d+. These examples assume that the regexp is
not set to "minimal match". Please read the Regular Expressions chapter for more details on the
regexp syntax.
Page 25/45