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)