[Share] regular text replaceable

Source: Internet
Author: User

Replacement of Regular Expressions

Regular Expressions are very powerful. Many professional editors provide regular expression search, but in terms of the replacement function, A reference to a capture group can be provided at most ("\ n" is used to code the nth capture group). Many functions cannot be implemented, either by coding and writing a specific program, you can either manually modify the settings or simply repeat them. For example, in the following scenario.

3*4 =?
-6*12 =?
9 *-5 =?
......

How do I replace the question mark with the result of multiplication?

Because regular expressions process text, they cannot complete mathematical operations, nor execute methods in some programming languages, such as judgments or generate sequences.

Solution-regular text replaceable

In order to solve these common problems, I have compiled a regular text replacement tool, which allows the use of function expressions in the content to encapsulate the programming part, you only need to use a simple expression to complete complex replacement,

$ Function name (parameter 1, parameter 2, parameter 3)
$ Function name [alias reference] (parameter 1, parameter 2, parameter 3)

Like the above problem, use a regular expression:

((-? \ D + )\*(-? \ D +) = )\?

And replacement expressions:

$ (1) $ * ($ (2), $(3 ))

Then execute the replace operation to complete the process.

  Function Description: $ (N) indicates the nth capturing group, and $ * (n, m) indicates the product of n and m.

If you need to add a line number to each line in the replacement, change the replacement expression:

$ Seq (1, 1), $ (1) $ * ($ (2), $(3 ))

To generate:

1, 3*4 = 12
2.-6*12 =-72
3. 9 *-5 =-45

  Function Description: $ Seq (n, m) is the sequence generator. n indicates the start value, and m indicates the increment value of the step.

The replicator not only implements four arithmetic operations and modulo operations, but also converts uppercase and lowercase letters and hexadecimal values (for example, hexadecimal to hexadecimal), Nvl, Iif in plsql, there are also sequence generators.

If these functions still cannot meet your needs, you can also expand and add your own functions, which is very convenient.

  The Help menu of the software contains detailed function descriptions, help for use, examples, and instructions for adding custom functions.

: Http://files.cnblogs.com/trytocatch/ ..zip

Note: According to netizens, jre1.6 or below has reported an error and has been corrected. jre1.6 can run normally, but cannot use a named capture group. jre1.7 can, or the original one.

Related Article

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.