Posts Tagged ‘资源管理器’

我叽歪软件:从xplorer2到Total Commander

不知道为什么,我非常喜欢的xplorer2这个资源管理器,老是无缘无故的崩坏,而且每次崩坏所有的设置、包括注册信息都会丢失。所有,现在又转回来使用TotalCMD

其实,很久以前,在使用xplorer2之前,使用的就是totalCMD。但是当看到xplorer2的简洁时,立刻就叛变了。但是,因为现在xplorer2老是崩坏,所以,不得不回到totalCMD了。不过,再次回来的时候,却发现totalCMD也已经改进了很多,特别喜欢的就是其中的批量替换功能了。它的批量替换功能非常强劲,竟然支持正则表达式。所以,这里也把其正则表达式的帮助,备份一下,以备不时只用。

totalCMD

Regular expressions

Regular expressions are a very powerful search tool. They allow to search for complex classes of words. Regular expressions are mainly meant for professionals, but can also be useful in the office for finding certain documents.

Total Commander supports regular expressions in the following functions:

  • - Commands – Search (in file name and file contents)
  • - In Lister
  • - In the Multi-Rename tool
  • - In the selection dialog

Regular expressions consist of normal characters and special characters, so-called meta-characters. The following characters are meta-characters or initial parts of meta-characters:
. \ ( ) [ ] { } ^ $ + * ? (only in character classes: – )

Normal characters:

test finds the string "test" in the searched text. Note: This finds "test" ANYWHERE in a file name or on a line in text.

Escape sequences:

A backslash \ starts an Escape sequence. Examples for escape sequences:

  • \t Tabstop
  • \xnn Character with hexadecimal code nn. Example: \x20 is the space character. The character table charmap.exe (if installed) shows the
  • character code of most special characters. You can use the Windows calculator in scientific mode to convert from decimal to hex.
  • \x{nnnn}
  • Unicode character with hexadecimal code nn. Note that Total Commander now uses Unicode for file names, so you need to use this notation for characters other than basic English.
  • \[ Left square bracket. Since the square brackets are meta-characters, they need to be written as \[ to search for them in the target string.
  • \\ Finds a backslash.
  • \. Finds a dot ("." alone finds any character, see below).

Character classes

Characters in square brackets build a character class. It will find exacly one character from this class. A dash allows to define groups, e.g. [a-z]. A ^ at the beginning finds all characters except for those listed.

Examples:

[aeiou] Finds exactly one of the listed vovels.
[^aeiou] Finds everything except for a vovel.
M[ae][iy]er Finds a Mr. Meier in all possible ways of writing: Mayer, Meyer, Maier, Meier. Very useful if you cannot remember the exact writing of a name.

Meta-characters

Here is a list of the most important meta-characters:

  • ^ Line start
  • $ Line end
  • . Any character
  • \w a letter, digit or underscore _
  • \W the opposite of \w
  • \d a digit
  • \D no digit
  • \s a word separator (space, tab etc)
  • \S no word separator
  • \b finds a word boundary (combination of \s and \S)
  • \B the opposite of \b

Iterators

Iterators are used for a repetition of the character or expression to the left of the iterator.

  • * zero or more occurances
  • + one or more occurances
  • {n} exactly n occurances
  • {n,} at least n occurances
  • {n,m} at least n and max. m occurances

All these operators are "greedy", which means that they take as many characters as they can get. Putting a question mark ? after an operator makes it "non-greedy", i.e. it takes only as many characters as needed.

Example: "b+" applied to the target string "abbbbc" finds "bbbb", "b+?" finds just "b".

Alternatives

Alternatives are put in round braces, and are separated by a vertical dash.

Example: (John|James|Peter) finds one of the names John, James or Peter.

Subexpressions for search+replace

Text parts in round braces are taken as subexpressions.

Example: To swap the title and interpret in the file name of an mp3 file, when they are separated by a dash (Title – Interpret.mp3), this can be solved like this:

  • Search for: (.*) – (.*)\.mp3
  • Replace by: $2 – $1.mp3
  • Here $1 means the text in the first brace, and $2 the text in the second brace.

Backreferences

\n Finds subexpression n another time in the search result.

Example: (.+)\1+ finds e.g. abab (where the first ab is found by .+ and the second by \1+ )

Modifiers

Modifiers are used for changing behaviour of regular expressions.

  • (?i) Ignore Upper-/lowercase. In Total Commander, this is the default for file names.
  • (?-i) Case-sensitive matching.
  • (?g) Switches on "greedy" mode (active by default)
  • (?-g) Turns off "greedy" mode, so "+" means the same as "+?"

The other modificators are not relevant for Total Commander, because the program only supports searching within one line.