A little record of replacing with regular expressions in eclipse (grouping with regular expressions)

Source: Internet
Author: User

Today at work encountered a point of trouble with the replacement, because the data class has been changed, the specific situation is this, the following code needs to be:

Player.skilldata[i].name

To be replaced by:

Player.skillData.getSkillInfo (i). Name

In particular, [i] is changed to getskillinfo (i), but the problem is that there is too much to modify, 200+ to use, and the parentheses are not necessarily "I", may be a variety of forms (such as "index "," _myindex ", etc.), can not be a manual one to change it ...

Finally, it is found that Eclipse supports the use of regular expressions, so just open the Find/Replace window, tick "regular expressions" and fill in the Find text box:

(skilldata\[) ([a-za-z0-9_$]*) (\])

In the Replace with text box, fill in:

Skilldata.getskillinfo ($)

All right, replace all, all the text under the current file will be replaced with the text we need.

Finally, focus on the grouping of regular expressions:

The regular expression stores the matched text in the "$" array, and we can use the $, $, $ ... access to all strings that match successfully, in an expression, a parenthesis represents a grouping.

Take our above expression example to see an example, such as the following text:

var name:string = Player.skilldata[i].name;

The results after matching are as follows:

$: skilldata[i]$1: skilldata[$2: i$3:]

We found that the whole text is always matched to $, and $ $, $ $ and $ $ are each corresponding to the 3 parentheses in our expression.

So, when you write the substitution, it means that the character in the second parenthesis that matches it is "I".

A little record of replacing with regular expressions in eclipse (grouping with regular expressions)

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.