TotalCommander (TotalCMD) Regular Expression

Source: Internet
Author: User
Tags character classes
Document directory
  • Common characters
  • Character Set combination (Character classes)
  • Metacharacters)
  • Iterators)
  • Optional characters (alternatives)
  • Subexpression (subexpressions)
  • Backreferences)
  • Modifiers)

I liked it a long time ago.Total CommanderBut older versions do not support trees, so they quit. SwitchXplorer2This file resource manager. However, I don't know what xplorer2 has been smoking recently, and the teacher crashes for no reason, so I started to use Total Commander again. However, when we use it again, we find that it is much better than the old version. So now we have decided to use Total Commander again.

I use the editor or resource manager. One of the important features is whether regular expressions are supported. This is because it can greatly improve the efficiency of search and replacement. This Total Commander is not disappointing.

The Regular Expression Function of Total Commander is based on TRegExpr (http://regexpstudio.com/) to implement a subset of regular expressions. The terminology below comes from the instructions of TRegExpr. The syntax is similar to the editor that generally supports RegEx. Some symbols, such as \ n, are not supported in TC. The following symbols and examples are verified and available.

Total Commander supports regular expressions in the following functions:

  • Search (file Search) in the Commands menu [RegEx is supported for file names and content]
  • Lister (view)
  • Multi-Rename tool in the Files menu (batch Rename)
  • Select group in the Mark (select) menu (add selection)

Regular Expressions include common characters, special characters, and metacharacters. Metacharacters are some identifiers with special meanings, such:. \ () [] {}^ $ + *?The special characters of these extended meanings are combined into flexible and powerful regular expressions.

Common characters

A normal string. Escape Sequence: the Escape sequence is guided by a backslash. For example:

  • \ XnnThe ASCII code value is a hexadecimal number nn character, for example\ X20Space.
  • \ TTAB, equivalent\ X09
  • \[And\]Left/right square brackets. Because square brackets are metacharacters, this escape sequence is used to represent the two symbols themselves.
  • \\Backslash
  • \.Periods (because they are also metacharacters ). Escape sequences can be used to match other metacharacters.

Example: Search for stringsSoft \ [microsoft]The expression is:Soft \ [microsoft \]

Character Set combination (Character classes)

A list of characters in square brackets with a value of any character in the list. A broken number indicates a range. For example, h-k indicates h, I, j, k, that is, the ASCII code table contains characters between h and k. The leading ^ represents characters outside the list. Escape characters, break numbers, metacharacters, and square brackets can also appear in character sets. When a break is used as a common character in a set, it should be placed at the header/end of the list or indicated by an escape sequence. When square brackets appear in a set as common characters, they should be placed in the header of the list or expressed as escape sequences.

Example:

  • [Aeiou]Any letter in aeiou.
  • [A-z ^ rt]Lowercase letters a to z, but not r and t.
  • M [AE] [iy] erMatching: Mayer, Meyer, Maier, and Meier.
  • [0-9a-zA-Z]Match All numbers and uppercase/lowercase letters.
  • [] \ D-]Matching the right square brackets, numbers, and dashes. It is equivalent to [\] 0-9 \-]
Metacharacters)

There are several special symbols:

  • ^For example, ^ step matches only 1st words in "step by step. TC works the same as \.
  • $For example, step $ matches only the last word in "step by step.
  • .Any character
  • \ WA letter, number, or underscore _, equivalent to [a-zA-Z0-9 _]
  • \ WSet of \ w
  • \ DNumber
  • \ DNon-numeric
  • \ SBlank characters, equivalent to [\ t \ n \ r \ f])
  • \ SNon-blank characters
  • \ BWord boundary refers to the position between two adjacent \ w and \ W. It should be used with other characters. For example, \ brun \ B will match the run following "how to run cmd: running", but will not match the run in running.
  • \ BSet of \ B
Iterators)

Indicates the number of repetitions of characters or expressions on the left.

  • *Zero or multiple times
  • +One or more times
  • {N}N times
  • {N ,}At least n times
  • {N, m}At least n times, at most m times

Repeated counting works in the "greedy" mode, that is, matching as many characters as possible. After the question mark is changed to "non-greedy" mode, that is, if there is a match, it will stop.
For example, in "abbbbc", the result of searching "B +" is "bbbb", and the result of searching "B + ?" Only "B" is returned ".

Optional characters (alternatives)

A group of characters separated by vertical bars. To avoid ambiguity, it is best to extend it with parentheses. For example: (John | James | Peter) matches any name in John, James, or Peter.

Matching is calculated from left to right. It is similar to the logic or operation in C language. If the expression on the left is satisfied, the expression on the right is not calculated. For example, if you search for (foo | foot) in "barefoot", you will get foo instead of foot.

Vertical bars | only common characters are used in character sets. Therefore, [look | like] indicates any character in lokie5 letters and vertical bars, rather than a word in look or like.

Subexpression (subexpressions)

The expression in parentheses is a subexpression. A complete regular expression may contain multiple subexpressions, which start from 1 to left. You can use $1, $2... to reference the values of Each subexpression.

For example, you can change the name of a file such as "singer name-qu ming.mp3.pdf"
Search :(. *)-(. *) \. mp3
Replace with: ipv2(%1%%then
$1 indicates the expression matching text in 1st pairs of brackets, and $2 indicates the expression matching text in 2nd pairs of brackets.

Backreferences)

\ 1 to \ 9. \ N is resolved to the content that matches the nth subexpression.

Example: Search in go12gogogoza34 (g. +) (\ d +) \ 1 + will search for go12gogogo, 1st expressions match go, 2nd expressions match 12, and the following three groups of go are matched by \ 1 +.

Modifiers)

Used to change the behavior of a regular expression. Before the expression. It acts on the expression on the right until another modifier or expression ends. You can insert multiple modifiers in an expression.

  • (? I)Case Insensitive. This is the default option when Total Commander searches for files.
  • (? -I)Case sensitive.
  • (? G)Enable the "greedy" mode (enabled by default)
  • (? -G)Disable greedy Mode

For example, if you want to search for only files starting with lowercase copy in copy1.txt and copy2.txt, use :(? -I) copy. * \. txt. If you do not use a regular expression, because the search file is case-insensitive by default, copy1.txt is also obtained when you search copy * .txt. Expression (? I) Saint -(? -I) in the result obtained by Petersburg, Saint can have different combinations of upper and lower cases, but the end word must be Petersburg.

Total Commander only supports a subset of regular expressions. For example, it only supports searching within a single line of text and does not support multiple rows.

Note: The subject content is not original, and most of the materials are from the network. The source address is not available!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.