How do I ... ?

How to use FAR?

The FIND command will always be the first command to be executed, since you have to define the set of files to operate on before you may apply any changes.

Select a base directory and a file name pattern such as *.txt to specify where and what to seach.

Once the FIND command has run, you can operate on the set of found files. To exclude a file from a replace, rename or other operation, just uncheck the checkbox in the left column of the result list.

Reuse parts of found text in replace text?

To capture some text in the find expression, put the respective pattern between brackets. You can then use it in the replace pattern with the code \1 (or \2, \3 ... if the find pattern contains more than one pair of brackets).

Example

Assume you want to decorate all html h2 headings with an inner anchor tag that carries the heading id as name attribute.

Thus changing
<h2 id="super">Super Title!</h2>
to
<h2 id="super"><a name="super">Super Title!</a></h2>
and so on.

You might use the following expression:
<h2 id="(\w+)">([^<]+)</h2>
with the following replacement text:
<h2 id="\1"><a name="\1">\2</a></h2>

Here the first bracket captures the id and the second bracket captures the heading it self. We use [^<]+, i.e. "any-character-but-<-at-least-once" to get the entire tag content. \1 and \2 refer to the respective brackets, called capturing groups, in the replacement text.

Read the regular expressions help for further details.

How to replace text in binary files?

Word documents and PDF files are binary files, not text files, even though they contain text. FAR on the other hand is a tool for text files, not binary files. As per default FAR does protect .docx, .pdf and other binary files from being altered. If you need to change such files, use an appropriate editor such as Microsoft Word or Adobe Writer.

However, there is an option in the FAR settings that, if disabled, allows to modify binary files: "Exclude binary files from replace operation". Use at your own risk.

How to find text spanning multiple line?

To add a line break into your search pattern, simply typ a second line like so:

Text that continues
on a second line.

No obscure construct such as "$\r?(?s:.)^" is required.

But there are situations when you do not know how many lines to find. Say you want to find all the Foo nodes in an XML document, that is all the text from <Foo> to </Foo>. If such a node can span any number of lines, you will need to apply the following expression:

<Foo>(?s:.+?)</Foo>

This combines the "dotall" flag ?s: with the quite exotic "reluctant" quantifier +?. The dotall flag makes the dot (.) represent line breaks also (wich it normaly does not). The "reluctant" quantifier +? prevents the regular expression parser from expanding the found text to the last closing </Foo> tag in the document.

How change file encoding?

First make sure the respective file has the right encoding assigned. The assigned encoding is disaplayed in the info view. Click with the right mouse button to get it. If the assigned encoding is not the files real (current) encoding, change the assigned encoding first. You can do this in the info view as well.

Next make sure only those files are checked (checkbox in left column of file list), that should have their encoding changed. Uncheck all other files, if any.

Eventually open the Tools menu and select the new encoding from the Change Encoding menu item.

Rename files with comma or special characters in name?

The Find... text box on the Rename tab takes a simple file name pattern by default. It thus treats the characters '*', '?', '#', '!' and ',' (comma) as special characters. If you want to enter a pattern that contains any of these, you must use regular expressions (tick the checkbox below the input field), because simple file name pattern have no escape mechanism.

Example 1

Assume you want to rename a number of files starting with "Betty, Alphonse" to start with "Alphonse Betty".

Just type "Betty, Alphonse" into the Find... field, tick the Regular Expression checkbox and type "Alphonse Betty" into the Replace With... field. That's it. It will work just fine, because comma and space are not special characters in regular expressions.

Example 2

Assume you want to remove a '?' character in a number of file names.

Type "\?" into the Find... field, tick the Regular Expression checkbox and leave the Replace With... field empty. While the question mark is a regular expression special character, the backslash is the regular expression escape character. Thus the escape sequence "\?" will be read as a simple question mark and be replaced with ... nothing.