What regular expression should I use to replace dimension constants
ID_FLOWER_开发者_StackOverflow社区128X128_JPG
ID_APPLE_100X100_ICO
ID_ORANGE_64X64_PNG
ID_SUN_DIAL_64X64_PNG
ID_COMPUTER_16X16_ICO
I have several constants which have been declared like this, what regular expression should I use to replace the dimensions of those constants (e.g. 16X16 or 128X128) to an empty string, so it should look like the following post replacement
ID_FLOWER_JPG
ID_APPLE_ICO
ID_ORANGE_PNG
ID_SUN_DIAL_PNG
ID_COMPUTER_ICO
Note: All such strings with the ID_ prefix
Find (assuming everything is in uppercase):
(ID_.+_)\d+X\d+_(.+)
The key bit in that regex is \d+X\d+
which looks for at least 1 numeric digit, followed by X, followed by at least 1 numeric digit.
Replace with:
$1$2
Try with:
(.*)_[0-9]*[Xx][0-9]*_(.*)
Replace with:
$1_$2
To test regexp in Eclipse use Eclipse Regular Expression (RegExp) Tester is a very nice plugin.
精彩评论