Got some big changes.
[size=150]Extended Backreferences (Replace Only)[/size]
People occasionally complain that RegReplace can’t use title case back references:
[pre=#232628] “test_case”: {
“find”: “([a-z])(?P[a-z]*)((?:_[a-z]+)+)”,
“replace”: “\u\1\L\g\E\U\g<3>\E”,
“greedy”: true
}[/pre]
Well this is because the regex engine that RegReplace uses is not Sublime’s built in regex engine, but instead uses Python. I won’t go into reasons why, but suffice it to say, I have reasons. Now Python doesn’t support title case backreferences in its regex engine. So I have been thinking about this recently and added some extended back references to handle this.
Now hold up, it isn’t exactly the same! Python strings already use \u, so \u wasn’t an option. So it is a sightly altered notation:
[pre=#232628] “test_case”: {
“find”: “([a-z])(?P[a-z]*)((?:_[a-z]+)+)”,
“replace”: “\c\1\L\g\E\C\g<3>\E”,
“greedy”: true
},[/pre]
See the difference? You have to use \c and \C instead of \u and \U. Now this is disabled by default and only works for the replace string (I’m not re-writing the regex parser for matches), so you have to enable it in your settings file by using:
[pre=#232628] // Use extended backreferences
“extended_back_references”: true[/pre]
There might be more in the future.
[size=150]Updated Plugin System (More Useful)[/size]
Also, I recently realized the plugin system was not that good in its current state. So I simplified it.
You still define a plugin the same way (plugins are referenced like importing a python module with Packages as your root) User.rr_modules.:
[pre=#232628] “some_definition”: {
“find”: “some regex here”,
“replace”: “some optional replace here”,
“greedy”: true,
“case”: true,
“plugin”: “User.rr_modules.useful_stuff”,
“args”: {“some_plugin_rguments”: “if_desired”}
},[/pre]
And I have provided a simple example on the repo you can try out. Now you just define a function called replace and it accepts a match object and optional arguments (I show them in the example just to remind you you can use them):
[pre=#232628]def replace(m, **kwargs):
text = "Here are your groups: "
for group in m.groups():
if group is not None:
text += “(%s)” % group
return text[/pre]